使用Maven打包可执行jar

SpringBoot工程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<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工程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<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文件,可以直接运行。

如何打包

1
mvn clean install package

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

1
nohup java -jar test-0.0.1-SNAPSHOT-jar-with-dependencies.jar >test.log 2>&1 &
# Jar, Maven

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×