1. 程式人生 > >打包Spring Boot工程

打包Spring Boot工程

在intellij idea 中,需要在maven中 新建 Run configuration,對應的command-line 為 :clean install spring-boot:repackage Pom.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>liwei.test</groupId>  
  5.     <artifactId>spring-boot</artifactId>  
  6.     <version>0.0.1-SNAPSHOT</version>  
  7.     <packaging>jar</packaging>  
  8.     <properties>  
  9.         <java.version>1.7</java.version>  
  10.         <start-class>com.test.springboot.Startup</start-class>  
  11.     </properties>  
  12.     <!-- Inherit defaults from Spring Boot -->  
  13.     <parent>  
  14.         <groupId>org.springframework.boot</groupId>  
  15.         <artifactId>spring-boot-starter-parent</artifactId>  
  16.         <version>1.0.1.RELEASE</version>  
  17.     </parent>  
  18.     <!-- Add typical dependencies for a web application -->  
  19.     <dependencies>  
  20.         <dependency>  
  21.             <groupId>org.springframework.boot</groupId>  
  22.             <artifactId>spring-boot-starter-web</artifactId>  
  23.         </dependency>  
  24.     </dependencies>  
  25.     <build>  
  26.         <pluginManagement>  
  27.             <plugins>  
  28.                 <plugin>  
  29.                     <artifactId>maven-compiler-plugin</artifactId>  
  30.                     <configuration>  
  31.                         <source>1.7</source>  
  32.                         <target>1.7</target>  
  33.                     </configuration>  
  34.                 </plugin>  
  35.             </plugins>  
  36.         </pluginManagement>  
  37.     </build>  
  38.     <repositories>  
  39.         <repository>  
  40.             <id>spring-snapshots</id>  
  41.             <url>http://repo.spring.io/snapshot</url>  
  42.             <snapshots>  
  43.                 <enabled>true</enabled>  
  44.             </snapshots>  
  45.         </repository>  
  46.         <repository>  
  47.             <id>spring-milestones</id>  
  48.             <url>http://repo.spring.io/milestone</url>  
  49.         </repository>  
  50.     </repositories>  
  51.     <pluginRepositories>  
  52.         <pluginRepository>  
  53.             <id>spring-snapshots</id>  
  54.             <url>http://repo.spring.io/snapshot</url>  
  55.         </pluginRepository>  
  56.         <pluginRepository>  
  57.             <id>spring-milestones</id>  
  58.             <url>http://repo.spring.io/milestone</url>  
  59.         </pluginRepository>  
  60.     </pluginRepositories>  
  61. </project>  

配置Maven Build-Run Configurations

Goals:org.apache.maven.plugins:maven-jar-plugin:2.4:jar org.springframework.boot:spring-boot-maven-plugin:1.0.1.RELEASE:repackage

必須選擇先maven後spring-boot-maven

如果這個地方不配置的話,會出錯:

Java程式碼  收藏程式碼
  1. [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.0.1.RELEASE:repackage (default-cli) on project spring-boot: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:1.0.1.RELEASE:repackage failed: Source must refer to an existing file -> [Help 1]  
  2. [ERROR]   
  3. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.  
  4. [ERROR] Re-run Maven using the -X switch to enable full debug logging.  
  5. [ERROR]   
  6. [ERROR] For more information about the errors and possible solutions, please read the following articles:  
  7. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException