Punter Vicky
Punter Vicky

Reputation: 16992

Adding a jar in WEB-INF\lib in POM

I have few jar files which I am not getting from any repositories.I have these jar files in WEB-INF\lib folder for src directory. Is there a way to add these as dependencies in POM without specifying the actual path of the jar files (relative path is fine..)?

Upvotes: 20

Views: 24920

Answers (5)

Premraj
Premraj

Reputation: 74581

Using Apache Maven Dependency Plugin

  • mvn dependency:copy-dependencies and you will find target/dependencies folder filled with all the dependencies, including transitive.
  • while downloading dependencies face issues, use mvn dependency:purge-local-repository and try again.

Using eclipse:

  1. Right click on Properties of the project.
  2. Select Deployment Assembly option.
  3. Click on Add button.
  4. Select Java Build Path Entries as follows.

enter image description here

  1. Click on Next to get the following wizard:
    enter image description here

  2. Select Maven Dependencies.

  3. Click on finish.

Upvotes: 4

Raghuram
Raghuram

Reputation: 52645

You can define the dependencies as follows:

<dependency>
    <groupId>my.group</groupId>
    <artifactId>my.artifact</artifactId>
    <version>a.b</version>
    <scope>system</scope>
    <systemPath>${basedir}/WEB-INF/lib/my.artifact.jar</systemPath>
</dependency>

Essentially you specify the scope as <system> to indicate to maven not to look for this in a repository and <systemPath> to indicate where it is. This would be an absolute path, but can take maven properties. Details here.

You would do this for each such jar that you have.

Upvotes: 23

Gaurav
Gaurav

Reputation: 1516

You can use ${project.baseuri} to get the path of your project and then go to the WEB_INF/lib directory from there. This page has a list of such properties that you can access in your pom.

Upvotes: 1

Arnout Engelen
Arnout Engelen

Reputation: 6897

As Guillaume correctly points out, just install the jars into your local/corporate repository.

If that is impossible for some reason, use the ${basedir} property

Upvotes: 1

Guillaume Polet
Guillaume Polet

Reputation: 47608

You should install these files in your local repository. Ideally, you have a shared repository installed on your local machine or on a remote server (Nexus, Artifactory, Archiva) and you deploy your jars to that repository.

To install a file locally, you can use the following command (taken from the Maven install plugin website):

mvn install:install-file -Dfile=your-artifact-1.0.jar \
                     [-DpomFile=your-pom.xml] \
                     [-Dsources=src.jar] \
                     [-Djavadoc=apidocs.jar] \
                     [-DgroupId=org.some.group] \
                     [-DartifactId=your-artifact] \
                     [-Dversion=1.0] \
                     [-Dpackaging=jar] \
                     [-Dclassifier=sources] \
                     [-DgeneratePom=true] \
                     [-DcreateChecksum=true]

In your pom, you can then reference those jars as regular dependencies. For more information on the Maven Install Plugin, take a look at their website.

Upvotes: 4

Related Questions