EN
Maven - built-in jar files into target jar file
9
points
In this short article, we would like to show how to built-in imported *.jar files into output *.jar file in Java Maven Project.
Quick solution (set includeSystemScope to true for spring-boot-maven-plugin):
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
Note: go to this article to know how to include
*.jarfiles from file system into the project.
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>
<build>
<finalName>my-project</finalName>
<plugins>
...
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
...
</plugins>
</build>
</project>