Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: How to include jars in Eclipse, which are not available in repository?

I have copied the JARs into src\main\webapp\WEB-INF\lib.
I use eclipse. If I add the jars one-by-one to Project-> Java Build Path-> Add jars, then I do Project-> Maven-> Update Project Configuration, they are removed by Maven. And Eclipse shows errors, which contain " xxx cannot be resolved".

Env:
Eclipse Java EE IDE for Web Developers.
Version: Indigo Service Release 1
Build id: 20110916-0149

m2e - Maven Integration for Eclipse 1.0.100.20110804-1717

Note: I don't want to create my own Maven repository. It will be just used once.
How should I proceed ?

like image 633
fjjiaboming Avatar asked Oct 06 '11 10:10

fjjiaboming


People also ask

How do I add a missing jar to Maven dependencies in Eclipse?

You can find this in Window > Preferences > Maven > User Settings , and then point Global Settings to your external maven settings. xml . Then i removed the broken projects and re-added them, and the Maven Dependencies library appeared again. Save this answer.

Why can I not add external JARs in Eclipse?

Can anyone help? If your project builds with Java 9+ make sure you've selected Classpath (as shown here). You should also be able to add the JAR with right-click on the project > Build Path > Add External Archives....


2 Answers

Not all libraries can be found in a public Maven repository, for example your own libraries or proprietary libraries. Anyway first you can search the Maven Repository, maybe some of them are there.

In case they are really not there, and you don't want to install Nexus or Artifactory, you can choose one of these two approaches:

  • install the jars in your local repository cache, no need to create a special repository. See the instructions on mkyong.

  • another approach is using system dependencies, you just put a path to reach the Jar in the filesystem. It's a less recommended approach, but if you really want it will work. Here is the official documentation.

like image 50
stivlo Avatar answered Sep 26 '22 16:09

stivlo


Add this an a Systems Dependency.


In case you want to add this (this uses jquantlib as example) to the maven local repo use:

mvn install:install-file -Dfile=./jquantlib-0.2.4.jar -DgroupId=org.jquantlib -DartifactId=jquantlib -Dversion=0.2.4 -Dpackaging=jar

In order to do this I use a batch file

@echo off

cd lib

CMD /C "mvn install:install-file -Dfile=./jquantlib-0.2.4.jar -DgroupId=org.jquantlib -DartifactId=jquantlib -Dversion=0.2.4 -Dpackaging=jar"
CMD /C "mvn install:install-file -Dfile=./jquantlib-helpers-0.2.4.jar -DgroupId=org.jquantlib -DartifactId=jquantlib-helpers -Dversion=0.2.4 -Dpackaging=jar"
CMD /C "mvn install:install-file -Dfile=./jquantlib-samples-0.2.4-ubber.jar -DgroupId=org.jquantlib -DartifactId=jquantlib-ubber -Dversion=0.2.4 -Dpackaging=jar"
CMD /C "mvn install:install-file -Dfile=./jquantlib-samples-0.2.4.jar -DgroupId=org.jquantlib -DartifactId=jquantlib-samples -Dversion=0.2.4 -Dpackaging=jar"

CMD /C "mvn install:install-file -Dfile=./ta-lib-0.4.0.jar -DgroupId=com.tictactec -DartifactId=ta-lib -Dversion=0.4.0 -Dpackaging=jar"

You can use a similar script file on other systems.

like image 42
Suminda Sirinath S. Dharmasena Avatar answered Sep 25 '22 16:09

Suminda Sirinath S. Dharmasena