Spring Boot Maven 打包 Jar

时间:2023-03-08 15:37:09
Spring Boot Maven 打包 Jar

Maven pom.xml 必须包含

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

完整pox.xml

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

linux下执行jar

    1. nohup java -Xmx512M -Xms512M -Djava.security.egd=/dev/urandom -jar message-service-1.0-SNAPSHOT.jar > /dev/null 2>&1 &