码迷,mamicode.com
首页 > 编程语言 > 详细

Spring Boot Maven 打包可执行Jar文件!

时间:2018-05-19 12:08:11      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:sdn   alt   maven   plain   schema   tools   conf   common   water   

Maven pom.xml 必须包含

 

[plain] view plain copy
 
  1. <packaging>jar</packaging>  

 

 

 

[html] view plain copy
 
  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

 

[html] view plain copy
 
  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.       
  5.     <groupId>com.feedback</groupId>  
  6.     <artifactId>feedback-service</artifactId>  
  7.     <version>0.1.0</version>  
  8.     <packaging>jar</packaging>  
  9.   
  10.     <properties>  
  11.         <java.version>1.8</java.version>  
  12.     </properties>  
  13.       
  14.     <parent>  
  15.         <groupId>org.springframework.boot</groupId>  
  16.         <artifactId>spring-boot-starter-parent</artifactId>  
  17.         <version>1.3.0.RELEASE</version>  
  18.     </parent>  
  19.       
  20.     <dependencies>  
  21.         <!-- spring boot -->  
  22.         <dependency>  
  23.             <groupId>org.springframework.boot</groupId>  
  24.             <artifactId>spring-boot-starter-web</artifactId>  
  25.         </dependency>  
  26.         <dependency>  
  27.             <groupId>org.springframework.boot</groupId>  
  28.             <artifactId>spring-boot-starter-data-jpa</artifactId>  
  29.         </dependency>  
  30.           
  31.         <!-- mysql数据库 -->  
  32.         <dependency>  
  33.             <groupId>mysql</groupId>  
  34.             <artifactId>mysql-connector-java</artifactId>  
  35.         </dependency>  
  36.           
  37.         <!-- commons-lang -->  
  38.         <dependency>  
  39.             <groupId>commons-lang</groupId>  
  40.             <artifactId>commons-lang</artifactId>  
  41.             <version>2.6</version>  
  42.         </dependency>  
  43.     </dependencies>  
  44.       
  45.     <!-- jar -->  
  46.     <build>  
  47.         <plugins>  
  48.             <plugin>  
  49.                 <groupId>org.springframework.boot</groupId>  
  50.                 <artifactId>spring-boot-maven-plugin</artifactId>  
  51.                 <configuration>  
  52.                     <fork>true</fork>  
  53.                 </configuration>  
  54.             </plugin>  
  55.         </plugins>  
  56.     </build>  
  57. </project>  



 

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

技术分享图片

 

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

 

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

 

java -jar 运行jar包 即可

技术分享图片

 

 

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

技术分享图片

linux下执行jar

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

Linux下还有一个特殊的文件/dev/null,它就像一个无底洞,所有重定向到它的信息都会消失得无影无踪。

 >/dev/null 2>&1

注意:此处的顺序不能更改,否则达不到想要的效果,此时先将标准输出重定向到 /dev/null,然后将标准错误重定向到标准输出,由于标准输出已经重定向到了/dev/null,因此标准错误也会重定向到/dev/null,于是一切静悄悄:-)

 

 

技术分享图片

Spring Boot Maven 打包可执行Jar文件!

标签:sdn   alt   maven   plain   schema   tools   conf   common   water   

原文地址:https://www.cnblogs.com/zhengmantoua/p/9059775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!