maven构建包含依赖的jar包
Posted nnsword
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了maven构建包含依赖的jar包相关的知识,希望对你有一定的参考价值。
maven构建包含依赖的jar包有两种方式
注意:如果有父pom的话,尽量通过父项目进行整体构建、打包
一、直接包含到jar包中
<!-- Maven Assembly Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>com.zdww.biyi.example.project.LogApp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
二、将依赖的jar复制到lib目录
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.zdww.biyi.example.project.LogApp</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- 拷贝依赖的jar包到lib目录 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
$project.build.directory/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
运行
java -jar xxx.jar
以上是关于maven构建包含依赖的jar包的主要内容,如果未能解决你的问题,请参考以下文章