-1

I have a group of about 20+ third party jars that I need to add to the RUNTIME of an Eclipse Maven project written in Java. These jars are not available from mvnrepository.com. How can I accomplish this?

I tried Build Path.. Configure Build Path and added the jars manually, but this does not make the jar APIs available in Spring MVC controllers because the jars were added to the Build Path and not to the RUNTIME.

I then tried Project Properties -> Deployment Assembly -> Add -> Archives from file system as per this other posting. This imported the jars into /WEB-INF/lib, but did not make their APIs available.

I then read these instructions for importing 3rd party jars into a maven project, but the instructions say to use this line of code mvn install:install-file -Dfile=<path-to-file>. As you can see, this code only specifies one jar, when I have over 20 third party jars to add. The maven link also does not specify where or when to type the code.

Do I navigate the terminal to the root directory of the Maven repository and then type that line of code with 20 variations, once for each jar?

And do I repeat this every time I do a Maven update from within Eclipse? Clearly there has to be an easier way.

What is the easiest and most effective way to get Eclipse Maven to add all 20+ jars to the runtime of my project, so that my Spring mvc controllers can call the APIs when I try Run As... Run on server, and so that the jars are also bundled up with any war files that get created by Eclipse Maven?**

Edit

@DaveNewton suggested writing a shell script. How would such a script look?

I tried mv /path/to/all/the/jars/* /path/to/workspace/MyApp/src/main/webapp/WEB-INF/lib/ and then typed F5 to make the jars visible in the /WEB-INF/lib folder, but this did not resolve the compilation errors from the code elsewhere in the project that calls the API, even after Project... Clean.

Also, I would like for the Eclipse Maven plugin to be able to manage this as much as possible.

Edit 2

As per @alainlompo's suggestion, I imagine a script that includes the following commands, and then the dependency addition below it. Here is what might be in the script:

mvn install:install-file -Dfile=/thefirst.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar  

mvn install:install-file -Dfile=/thesecond.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar  

mvn install:install-file -Dfile=/thethird.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar  

mvn install:install-file -Dfile=/thefourth.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar  

mvn install:install-file -Dfile=/thefifth.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar  

mvn install:install-file -Dfile=/thesixth.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar  

mvn install:install-file -Dfile=/theseventh.jar -DgroupId=my.group.id -DartifactId=myartifactid -Dversion={version} -Dpackaging=jar  

And so on for all 20+ jars.

Here is what the dependency tag in the pom.xml might be:

<dependency>
  <groupId>my.group.id</groupId>
  <artifactId>myartifactid</artifactId>
  <version>what goes here?</version>
</dependency>  

I would guess I would add some symbols to the groupid to make sure that Maven cannot find anything with the same name at mvnrepository.com. This way the Eclipse Maven update could be used. But what do I use for the version number? Many of the jars have different version numbers.

Also note I am using Linux. What would the actual shell script and dependency tag look like?

halfer
  • 19,824
  • 17
  • 99
  • 186
CodeMed
  • 9,527
  • 70
  • 212
  • 364
  • You should be able to install them locally and refer to them as usual in your Eclipse project, assuming you're using an Eclipse with some form of Maven plugin. – Dave Newton Apr 20 '15 at 19:16
  • Write a shell script to do it to all the jars in a directory or something. I mean, that's kind of the option. – Dave Newton Apr 20 '15 at 19:22
  • *Also, I would like for the eclipse maven plugin to be able to manage this as much as possible.* then you need a real repository server if you want this, you can not have your cake and eat it too! –  Apr 20 '15 at 19:29
  • he meant write a script to add them to your local maven repository. you seriously need to read up on what maven actually does and how maven actually works –  Apr 20 '15 at 19:31
  • @JarrodRoberson That is fine. "As much as possible", could mean very little. For example, when jars are added to the eclipse build path manually, the eclipse maven plugin seems to bundle them into a resulting war file well enough. – CodeMed Apr 20 '15 at 19:31

1 Answers1

1

I think the simplest way to solve this issue is to add your jars to your maven local repository. There is answer for this on SO here and also here. The jars will then be available in Eclipse but also outside eclipse for any of your project that is using maven as a build tool and where the jar is correctly referenced (with the groupId, artifactId and version dependency informations properly provided) as in the following example:

<dependencies>
    ....
    <dependency>
        <groupId>org.matlabcontrol</groupId>
        <artifactId>matlabcontrol</artifactId>
        <version>4.1.0</version>
     </dependency>
</dependencies>

And then you may easily write a .bat or a .sh (depending on the OS) that will do this operation once and for all.

[EDIT] @CodeMed regarding the jars that are behind the link that you've shared in your comments, some of them are related to each others and therefore will share the same version as the same groupId and most certainly different artifactIds

Example:

  • org.eclipse.emf.common_2.5.0.v200906151043.jar
  • org.eclipse.emf.ecore.xmi_2.5.0.v200906151043.jar

Obviously the suffixed 4 parts number is the version number of the jar. So You already have the version number and since it is common to many jar it is to your advantage to define a variable for it in your .bat file and a property for it in your pom.xml file.

Also the groupId will generaly be the same for all related jars. Therefore you could suspect that the groupId would be org.eclipse.emf, and if you google this: maven dependency for org.eclipse.emf + 2.5.0.v200906151043you would find among other links a link to a pom.xml file on a related github project with the following depency informations

maven dependency

I would now be logical to suspect that the artifactId is what's left from the name of the jar commonin one case and ecore.xmiin the other case. This will be checked against a little googling or on Mvnrepository (for example here where we see that this artifact id is also prefixed by the group id)

Therefore we would write the following kind of instructions in a .bat file to install these jars in our local repository

First define a variable to hold the version number

set eclipseEmfVersion=2.5.0.v200906151043
call mvn install:install-file -Dfile=org.eclipse.emf.ecore.xmi_2.5.0.v200906151043.jar -DgroupId=org.eclipse.emf -DartifactId=org.eclipse.emf.ecore.xmi -Dversion=%eclipseEmfVersion% -Dpackaging=jar
call mvn install:install-file -Dfile=org.eclipse.emf.common_2.5.0.v200906151043.jar -DgroupId=org.eclipse.emf -DartifactId=common -Dversion=%eclipseEmfVersion% -Dpackaging=jar

In the case of the second jar however I find on MvnRepository that the artifactId does not set the groupId as its prefix (see here)

Note also that in a .bat file you need to use call mvn (instead of simply mvn as you would do had you only one instruction to run) to be able to execute many maven instruction sequentially.

On the same pattern you can distinguish another group of related jars with the groupId: org.openhealthtools.mdht.uml.cdaand version number 1.2.0.201405161834. You can apply the same approach to install them in your local repository

Here is the successfull test I run (from a bat file that I created in the same directory where I unzip your file) using the first four jars in your list of jars

call mvn install:install-file -Dfile=net.sourceforge.lpg.lpgjavaruntime_1.1.0.v200803061910.jar -DgroupId=net.sourceforge.lpg  -DartifactId=net.sourceforge.lpg.lpgjavaruntime -Dversion=1.1.0.v200803061910 -Dpackaging=jar

call mvn install:install-file -     Dfile=org.apache.commons.lang_2.3.0.v201005080501.jar -     DgroupId=org.apache.commons -DartifactId=lang -Dversion=2.3.0.v201005080501 -     Dpackaging=jar

call mvn install:install-file -    Dfile=org.eclipse.core.runtime_3.8.0.v20120521-2346.jar -    DgroupId=org.eclipse.birt.runtime -DartifactId=org.eclipse.core.runtime -    Dversion=3.8.0.v20120521-2346 -Dpackaging=jar

set cdaversion=1.2.0.201405161834

call mvn install:install-file -    Dfile=org.openhealthtools.mdht.uml.cda.ihe_1.2.0.201405161834.jar -     DgroupId=org.openhealthtools.mdht.uml.cda -DartifactId=ihe -     Dversion=%cdaversion% -Dpackaging=jar

You can easily complete the .bat and after running you may manually check the successfull installation of all the jars in your maven local repository.

Community
  • 1
  • 1
alainlompo
  • 4,414
  • 4
  • 32
  • 41
  • @CodeMed, yes basically. Regarding the version your project's technical specifications would specify what version to use. if your jars are all independant from each other then you will have as much version numbers as jars. But in some case you have jars that are kind of related and may have the same version number and in such a case you define a property with the common version number ( will generaly looks like x.y.z.t for example 3.2.0.1, ...) and use it. One property would go for your .sh or .bat and simalarly you can define one also for your pom.xml file – alainlompo Apr 20 '15 at 20:11
  • @CodeMed you generally keep the groupId and the artifactId along with the version as defined by the editor of the jar, otherwise your project would not be portable if you deploy in the remote environment that does not have your same local repository but have the original jar in another maven repo – alainlompo Apr 20 '15 at 20:14
  • @CodeMed also some of the third party jars often come with their pom.xml (which contains the jar dependency informations). You can install it with a similar command as: mvn install:install-file -Dfile= -DpomFile= – alainlompo Apr 20 '15 at 20:23
  • @CodeMed in case you have a name of your library and it has been a known library by the past but has stopped being hosted by a public maven repo, you may still google around that name of a fully qualified class name it contains. Example google this: `maven dependency for Apache commons` would lead you to `http://mvnrepository.com. It contains the dependency informations and also the downloadable jars – alainlompo Apr 20 '15 at 20:32
  • @CodeMed, sure I will. – alainlompo Apr 20 '15 at 20:42
  • @CodeMed, yes, I will edit my answer in just a minute – alainlompo Apr 20 '15 at 21:48
  • @CodeMed - glad I could help. I would love to continue to develop the search but SO is asking us to rather use the chat room that comments. I will be looking forward to hearing from you soon. – alainlompo Apr 21 '15 at 02:11
  • @CodeMed, meet me in the chat room pleae – alainlompo Apr 21 '15 at 21:23
  • @CodeMed your votes were reversed by SO (see here: http://stackoverflow.com/help/serial-voting-reversed) – alainlompo Apr 22 '15 at 06:55
  • cool. I did also, and I am looking forward for the next opportunity to do something nice with you. Best wishes. – alainlompo Apr 23 '15 at 22:31