Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using jar I already have in Maven

 
Antonio Fornie
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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'.
 
Antonio Fornie
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic