maven笔记-将本地jar包打包进可执行jar中

时间:2022-02-05 20:09:44

参考资料:http://www.cnblogs.com/richard-jing/archive/2013/01/27/Maven_localjar.html

使用本地jar

<dependencies>
<dependency>
<groupId>org.richard</groupId>
<artifactId>my-jar</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/my-jar.jar</systemPath>
</dependency>
</dependencies>

注意:system scope引入的包,在使用jar-with-dependencies打包时将不会被包含,可以使用resources将本地包打进jar-with-dependencies

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>xxx-jar-with-dependencies</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<targetPath>lib/</targetPath>
<directory>lib/</directory>
<includes>
<include>**/my-jar.jar</include>
</includes>
</resource>
</resources>
</build>

生成的xxx-jar-with-dependencies.jar中,将会包含lib目录以及my-jar.jar,并且能够被在执行的时候被找到。