如图类似的maven项目,需要作为jar包导出
步骤一
给pom添加plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>D:/Program Files/Java/jdk1.8.0_144/bin/javac</executable>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<!--这部分可有可无,加上的话则直接生成可运行jar包 -->
<!-- <archive>
<manifest>
<mainClass>com.thanks.hehe.App</mainClass>
</manifest>
</archive> -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
注意:如果没有JDK会报错
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile)
步骤二
右键当前项目 ==> Run As ==> Maven build ==> Goals输入:clean assembly:assembly ==> Run
结果查看
控制台会打印打包的jar位置: