1.添加maven-assembly-plugin和maven-dependency-plugin

assembly:用于打可执行jar包

dependency: 导出依赖包

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifest>
<mainClass>com.netease.mail.yanxuan.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>

添加后会在Intellij 的maven窗口出现以下插件

用Intellij打可执行jar包-LMLPHP

用Intellij打可执行jar包-LMLPHP

2.点击上图中圈中命令的后会在项目下的target的件产生以下文件

用Intellij打可执行jar包-LMLPHP

3.将lib和run.jar两个文件上传到linux或者直接在windows下执行

Linux 下 运行jar包中的主类

java -cp "./*:./lib/*" -Xms512m -Xmx512m -Dinitmemcached=false -Dspring.profiles.active=test com.netease.mail.yanxuan.Main

windows

java -cp "./*;./lib/*" -Xms512m -Xmx512m -Dinitmemcached=false -Dspring.profiles.active=test com.netease.mail.yanxuan.Main

05-08 08:20