Spring Boot Maven 打包可执行Jar文件的实现方法

时间:2021-08-06 15:40:30

maven pom.xml 必须包含

?
1
<packaging>jar</packaging>
?
1
2
3
4
5
6
7
8
9
10
11
<build>
  <plugins>
    <plugin>
      <groupid>org.springframework.boot</groupid>
      <artifactid>spring-boot-maven-plugin</artifactid>
      <configuration>
        <fork>true</fork>
      </configuration>
    </plugin>
  </plugins>
</build>

完整pox.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
  xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelversion>4.0.0</modelversion>
  <groupid>com.feedback</groupid>
  <artifactid>feedback-service</artifactid>
  <version>0.1.0</version>
  <packaging>jar</packaging>
  <properties>
    <java.version>1.8</java.version>
  </properties>
  <parent>
    <groupid>org.springframework.boot</groupid>
    <artifactid>spring-boot-starter-parent</artifactid>
    <version>1.3.0.release</version>
  </parent>
  <dependencies>
    <!-- spring boot -->
    <dependency>
      <groupid>org.springframework.boot</groupid>
      <artifactid>spring-boot-starter-web</artifactid>
    </dependency>
    <dependency>
      <groupid>org.springframework.boot</groupid>
      <artifactid>spring-boot-starter-data-jpa</artifactid>
    </dependency>
    <!-- mysql数据库 -->
    <dependency>
      <groupid>mysql</groupid>
      <artifactid>mysql-connector-java</artifactid>
    </dependency>
    <!-- commons-lang -->
    <dependency>
      <groupid>commons-lang</groupid>
      <artifactid>commons-lang</artifactid>
      <version>2.6</version>
    </dependency>
  </dependencies>
  <!-- jar -->
  <build>
    <plugins>
      <plugin>
        <groupid>org.springframework.boot</groupid>
        <artifactid>spring-boot-maven-plugin</artifactid>
        <configuration>
          <fork>true</fork>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

进入到项目目录下运行:mvn clean package

Spring Boot Maven 打包可执行Jar文件的实现方法

会在项目目录下target文件夹中生成jar

如上生成的jar文件在:d:\programmer\eclipse\feedback-service\target  文件夹中

java -jar 运行jar包 即可

Spring Boot Maven 打包可执行Jar文件的实现方法

java -jar 运行jar包时使用外部配置文件application.properties

Spring Boot Maven 打包可执行Jar文件的实现方法

Spring Boot Maven 打包可执行Jar文件的实现方法

总结

以上所述是小编给大家介绍的spring boot maven 打包可执行jar文件的实现方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!

原文链接:http://blog.csdn.net/smilecall/article/details/56288972