• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using jar I already have in Maven

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic