spring-boot-maven-plugin 插件的做用(轉)

OM 文件中添加了「org.springframework.boot:spring-boot-maven-plugin」插件。在添加了該插件以後,當運行「mvn package」進行打包時,會打包成一個能夠直接運行的 JAR 文件,使用「Java -jar」命令就能夠直接運行。這在很大程度上簡化了應用的部署,只須要安裝了 JRE 就能夠運行。html

能夠在POM中,指定生成 的是Jar仍是War。java

<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">
<!-- ... -->
<packaging>jar</packaging>
<!-- ... -->
</project>spring

 

你還能夠指定要執行的類,若是不指定的話,Spring會找有這個【public static void main(String[] args)】方法的類,當作可執行的類。apache

若是你想指定的話,能夠用下面兩個方法:maven

1,若是你的POM是繼承spring-boot-starter-parent的話,只須要下面的指定就行。ide

<properties>
    <!-- The main class to start by executing java -jar -->
    <start-class>com.mycorp.starter.HelloWorldApplication</start-class>
</properties>

2,若是你的POM不是繼承spring-boot-starter-parent的話,須要下面的指定。spring-boot

 

 

    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <version>1.3.5.RELEASE</version>
      <configuration>
        <mainClass>${start-class}</mainClass>
        <layout>ZIP</layout>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>repackage</goal>
          </goals>
        </execution>
      </executions>
    </plugin>

 

from:ui

http://docs.spring.io/spring-boot/docs/current/maven-plugin/usage.html
http://stackoverflow.com/questions/23217002/how-do-i-tell-spring-boot-which-main-class-to-use-for-the-executable-jar
http://docs.spring.io/spring-boot/docs/current/maven-plugin/repackage-mojo.html
http://udn.yyuap.com/doc/Spring-Boot-Reference-Guide/III.%20Using%20Spring%20Boot/13.1.4.%20Using%20the%20Spring%20Boot%20Maven%20plugin.html
http://www.ibm.com/developerworks/cn/java/j-lo-spring-boot/#listing1spa

相關文章
相關標籤/搜索