EN
Maven - add *.jar library to *.pom (import local *.jar file)
4
points
In this short article, we would like to show how to import *.jar
file as a dependency inside *.pom
configuration in Java Maven Project.
Quick solution:
<dependencies>
<dependency>
<groupId>my-jar</groupId>
<artifactId>my-jar</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>/path/to/my.jar</systemPath>
</dependency>
</dependencies>
Note: see to the below example to know how to use a relative path to
*.jar
file,
e.g.${pom.basedir}/lib/my.jar
or${project.basedir}/lib/my.jar
.
Practical example
In this section, *.jar
files are located in lib/
directory located in the project (on the same level where *.pom
is placed).
Project structure:
/C/
|
+-- my-project/
|
+-- lib/
| |
| +-- my.jar
|
+-- src/
| |
| +-- Program.java
|
+-- pom.xml
pom.xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my-project</groupId>
<artifactId>my-project</artifactId>
<version>1.0.0</version>
<name>my-project</name>
<packaging>jar</packaging>
...
<dependencies>
...
<dependency>
<groupId>my-jar</groupId>
<artifactId>my-jar</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/my.jar</systemPath>
</dependency>
...
</dependencies>
</project>
Where:
<groupId>
,<artifactId>
and<version>
describes an attached library - useful when JAR file is not described,<scope>
withsystem
value, indicates file loading from the file system,<systemPath>
indicates path to*.jar
file the file system,${pom.basedir}
represents the directory where thepom.xml
file is located.