aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Using jar I already have in Maven Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Using jar I already have in Maven" Watch "Using jar I already have in Maven" New topic
Author

Using jar I already have in Maven

Antonio Fornie
Ranch Hand

Joined: Aug 07, 2008
Posts: 117
Hello.

I have a project that started months ago, and I want to use it with Maven 2. I already created the needed structure, the only problem is the libraries (dependencies). How can I avoid Maven from downloading jar that I already have on my machine? By the way, I'll have to write the name, version... I guess it won't be easy to know the version of my jars, except those with the version in their name.

Thank you very much.


I feel there must be far better ways to do what I do... that makes learning even funnier
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

The point of Maven is that it will download jars into a special area called the local repository, this is separate to the area with the jars already on your machine. However if you truly want to reference your local jar you can set the scope of that dependency to 'system'.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Antonio Fornie
Ranch Hand

Joined: Aug 07, 2008
Posts: 117
Thank you very much.

You talk about two separate areas, but I guess it's better to have it all in my local repository with the correct directory structure, isn't it?

For example, if I need two libraries: a.jar and b.jar and I already have a.jar. I guess I should put the two dependencies in my pom and then copy a.jar to my local repository. Am I right? Then Maven should look for them and finally download only the b.jar. That way the only thing I'd need to know is wich directory structure to use when placing a.jar by hand. Is this the right way to do it?

Thank you very much.

Antonio
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Antonio Fornie wrote:Thank you very much.
You talk about two separate areas, but I guess it's better to have it all in my local repository with the correct directory structure, isn't it?


Yes, you may have your jar for example at c:\mylibs\log4j-1.2.14.jar. If you use Maven it will automatically download the canonical version of that jar and generally put it in your $USER_HOMe/.m2/repository.

Antonio Fornie wrote:
For example, if I need two libraries: a.jar and b.jar and I already have a.jar. I guess I should put the two dependencies in my pom and then copy a.jar to my local repository. Am I right? Then Maven should look for them and finally download only the b.jar. That way the only thing I'd need to know is which directory structure to use when placing a.jar by hand. Is this the right way to do it?


Correct _if_ the jar you are dealing with is not already a Maven central jar (remember the Maven hosts 1000's of jars in its repository, so for most libs it will automatically download from central and place in your local).

If it is a 3rd party jar that Maven central does not have then yes you need to manually place it in your local repository, the directory structure is up to you but should obviously match the group-id you specify in your pom.xml

If this is your own jar that you've built from your source code then you actually want to be using mvn install to install that into your local repository.

Hope that helps!
Edwin Stephens
Greenhorn

Joined: Dec 30, 2008
Posts: 15
Hi Antonio,

If you have a 3rd-party jar file in your original project that has no version number on it, you can check if it already exists in the maven central repository using this tool:

http://www.jarvana.com/jarvana/digest-check

You upload the jar file and it generates md5 and sha1 checksums for the file and then checks to see if these checksums exist in the central repository. If the md5 or sha1 checksum is found, the tool will give you the dependency information (groupId, artifactId, version) for the jar file.

Hope that helps,
Edwin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using jar I already have in Maven
 
Similar Threads
Struts2 Reponse already committed errors in was6
Maven and Eclipse - updating jar to newer version
JBOSS and Mysql
how do i add a jar file externally as a maven dependency in eclipse?
Maven and parallel builds