一、使用maven
场景描述:需要将maven的依赖一并打到JAR里面。
可以这样定义POM文件
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.payment.test.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
这样打出来的包有两个:
test-1.0-SNAPSHOT-jar-with-dependencies.jar 与 test-1.0-SNAPSHOT.jar
执行命令
# java -jar test-1.0-SNAPSHOT-jar-with-dependencies.jar