且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Spring Boot中创建单个可执行文件战争

更新时间:2023-01-02 10:59:24

感谢斯蒂芬(Stephane)建议删除分类器并建议使用starter.io.

Thanks to Stephane for suggesting to remove the classifier and for suggesting to use starter.io.

我最初的问题是我在目标中得到两个战争文件: 1)Root.war和其他 2)Discovery-service-boot.war

My original problem was I was getting two war files in the target: 1) Root.war and the other 2) discovery-service-boot.war

我想,魔鬼在maven-war-plugin配置中.删除warName和outputDirectory的xml标记后,我得到了可执行文件war.

I guess, the devil was in the maven-war-plugin config. After I removed the xml tags for warName and outputDirectory, I'm getting the executable war.

我将发布最终的pom.xml,以使其他面临类似情况的人受益:

I'm posting the final pom.xml to benifit others facing similar situation:

http://maven.apache.org/xsd/maven-4.0.0.xsd> 4.0.0

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<artifactId>discovery-service</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>

<description>
    Discovery microservice to provide a service registry using Spring Cloud
    and Netflix Eureka for cloud native microservices.
</description>

<properties>
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>1.2.3.RELEASE</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka-server</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Brixton.SR1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-parent</artifactId>
            <version>Brixton.SR1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>