使用Maven打包可执行jar

SpringBoot工程

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
  <mainClass>com.wuwneze.springbootexample.SpringbootExampleApplication</mainClass>
</configuration>
<executions>
  <execution>
    <goals>
      <goal>repackage</goal>
    </goals>
  </execution>
</executions>
</plugin>

普通Java工程

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
  <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
  </descriptorRefs>
  <archive>
    <manifest>
      <mainClass>com.wuwenze.Main</mainClass>
    </manifest>
  </archive>
</configuration>
<executions>
  <execution>
    <id>make-assembly</id>
    <phase>package</phase>
    <goals>
      <goal>single</goal>
    </goals>
  </execution>
</executions>
</plugin>

使用该插件生成的jar包,带jar-with-dependencies后缀的jar文件,可以直接运行。

如何打包

mvn clean install package

题外话:如何让linux命令保持后台运行?

nohup java -jar test-0.0.1-SNAPSHOT-jar-with-dependencies.jar >test.log 2>&1 &
    原文作者:吴汶泽
    原文地址: https://segmentfault.com/a/1190000016961280
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞