views:

43

answers:

4

I have a .jar that I want included in my IDEA web application project that is using maven2 (pom.xml).

How can I add a .jar to my project that isn't using maven?

A: 

Trying to guess what the question is:

1) You have a maven project A with jar foo.jar
2) You have a non-maven project B that you want to use the same jar in (without using maven)
3) You are on windows?

If this is true, then:

Go grab the jar from c:\documents and settings\your_username\.m2\name_of_jar, and stick it in the WEB-INF/lib directory of project B

bwawok
+2  A: 

Easiest thing is to use maven:install-file to install the jar in your local repository, as follows (stolen from the docs:

mvn install:install-file -Dfile=path-to-non-maven.jar \
                      -DgroupId=some-id \
                      -DartifactId=some-artifact \
                      -Dversion=some-version \
                      -Dpackaging=jar

Then add it to your POM like any other dependency. If it needs to be shared with many people, you may consider setting up a local instance of something like Nexus or Artifactory (we use Artifactory where I work and it works well).

ig0774
A: 

The maven install:install-file is perfect for adding a local JAR to your caches, but if you're using a repository externally (i.e. Archiva or Nexus), then you're better off making it available to all with "mvn deploy:deploy-file" - similar arguments for that command.

Installing just locally means that if you purge your local cache for whatever reason (i've ended up doing this a number of times to solve this or that problem with corrupted local cache), then you loose the local JAR as well and need to remember to re-add it again. If it's in the local DSL repository through Nexus or Archiva, you're in good shape - just add the resulting groupId, artifactId into the POM and carry on.

heckj
+1  A: 

You basically have three options:

  • Install the jar in your local repository using install:install-file (see Guide to installing 3rd party JARs). This is pretty straightforward and easy but this will make your POM non portable. This might be an option if you are alone and doesn't plan to distribute your pom.xml.

  • Deploy the jar in a corporate repository using deploy:deploy-file. This is of course the ideal and preferred scenario in a corporate environment.

  • If you're not using a corporate repository but are still working in team, setup a file based repository and share it through your source repository.

Pascal Thivent