2014-10-11 117 views
3

我的POM如下。但是當我運行「mvn clean package」時,可執行JAR不會被創建。但是,當我刪除dependencyManagement元素並添加彈簧啓動作爲父POM時,一切正常。Spring Boot Maven插件無法創建可執行文件夾

我錯過了什麼?

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.example</groupId> 
    <artifactId>sample-boot</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <!-- Import dependency management from Spring Boot --> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-dependencies</artifactId> 
       <version>1.2.0.M2</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
    </dependencies> 

    <repositories> 
     <repository> 
      <id>spring-snapshots</id> 
      <url>http://repo.spring.io/snapshot</url> 
      <snapshots> 
       <enabled>true</enabled> 
      </snapshots> 
     </repository> 
     <repository> 
      <id>spring-milestones</id> 
      <url>http://repo.spring.io/milestone</url> 
     </repository> 
    </repositories> 

    <pluginRepositories> 
     <pluginRepository> 
      <id>spring-snapshots</id> 
      <url>http://repo.spring.io/snapshot</url> 
     </pluginRepository> 
     <pluginRepository> 
      <id>spring-milestones</id> 
      <url>http://repo.spring.io/milestone</url> 
     </pluginRepository> 
    </pluginRepositories> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-maven-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

回答

2

這是因爲插件是在第二種情況下在父級配置。如果你想管理自己的插件(即不使用父級),你必須明確地配置spring啓動插件(和其他)。

17

您需要自己配置彈簧引導Maven的插件:

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <version>1.1.8.RELEASE</version> 
      <executions> 
       <execution> 
        <goals> 
         <goal>repackage</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

顯然設置自己的插件版本。現在,如果您運行mvn install或mvn軟件包,則會生成可執行JAR。

1

當您使用Spring引導依賴關係管理(沒有使用spring-boot-starter-parent)時,您仍然可以保持依賴關係管理的好處,但不是插件管理,而是

這意味着你需要提供完整的插件(與版本和其他東西)。

+0

你有鏈接到文檔證實了這一點? – 2016-11-15 09:38:56

+0

[Yes](http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-build-systems.html#using-boot-maven-without-a-parent) – mladirazvijac 2017-01-22 16:06:40

0

鑑於是的pom.xml以創建可執行的jar文件

<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/maven-v4_0_0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>org.executablejar</groupId> 
<artifactId>demo</artifactId> 
<packaging>jar</packaging> 
<version>0.0.1-SNAPSHOT</version> 
<name>demo Maven Webapp</name> 
<url>http://maven.apache.org</url> 

<properties> 
    <java-version>1.8</java-version> 
    <docker.image.prefix>springDemo</docker.image.prefix> 
</properties> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.3.3.RELEASE</version> 
</parent> 

<dependencies> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-tomcat</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.tomcat.embed</groupId> 
     <artifactId>tomcat-embed-jasper</artifactId> 
    </dependency> 

</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
     </plugin> 
    </plugins> 
    <finalName>demo</finalName> 
</build> 

要創建可執行的jar,鍵入以下命令

$ mvn clean 
$ mvn install 

觀看視頻:https://youtu.be/Yy8RxjdcTfE

0

根據SpringBoot文件。 插件重寫你的清單,特別是它管理主要類和開始類條目,所以如果默認值不起作用,你必須在那裏配置那些(不在jar插件中)。在清單中的Main-Class實際上是由引導插件

SpringBoot Maven-plugin-not-creating-executable-jar

的佈局屬性如下改變控制按SpringBoot文檔爲我工作。

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <configuration> 
       <mainClass>YourSpringBootJavaClass</mainClass> 
       <layout>WAR</layout> 
      </configuration> 
      <executions> 
       <execution> 
        <goals> 
         <goal>repackage</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
    <finalName>yourwarfileName</finalName> 
</build> 
0

我一直在爲建設一個項目運行的JAR(Maven的POM)爲改變了一年多,最近的東西和JAR不再包含任何依賴性JAR文件。最後,在編寫本文時更新到最新的Spring啓動版本(1.5.2.RELEASE)解決了這個問題。

1

當您運行mvn package時,Spring Boot將確保您的應用程序將作爲測試引導。確保它在此期間不失效。

相關問題