How do i use Jar files as a dependency using IntelliJ with Maven? I have some jar's containing API codes but when I put them in my external library it gives an error saying it's missing.
Asked
Active
Viewed 9,189 times
3
-
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html – JB Nizet Sep 26 '15 at 15:06
1 Answers
4
The easiest way to do it is by installing the jar file in your local Maven repository, as JB Nizet already mentioned:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
See also How to add local jar files in maven project?
This works fine as long as you are only using your local Maven repository. However when others should be able to build your project, they will run into the same problem. So here the easiest way would be to install the jar file in proxy Maven repository if you have one (many companies do).
You could also reference the jar file as a system dependency:
<dependency>
<artifactId>..</artifactId>
<groupId>..</groupId>
<scope>system</scope>
<systemPath>${basedir}/lib/dependency.jar</systemPath>
</dependency>
There is also a very nice alternative: Maven: add a dependency to a jar by relative path