spring-boot-maven-plugin 外掛程式的作用

來源:互聯網
上載者:User

OM 檔案中添加了“org.springframework.boot:spring-boot-maven-plugin”外掛程式。在添加了該外掛程式之後,當運行“mvn package”進行打包時,會打包成一個可以直接啟動並執行 JAR 檔案,使用“java -jar”命令就可以直接運行。這在很大程度上簡化了應用的部署,只需要安裝了 JRE 就可以運行。

可以在POM中,指定產生 的是Jar還是War。

<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會找有這個【public static void main(String[] args)】方法的類,當做可執行檔類。

如果你想指定的話,可以用下面兩個方法:

1,如果你的POM是繼承spring-boot-starter-parent的話,只需要下面的指定就行。

<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的話,需要下面的指定。

    <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:

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/#listing1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.