3

We are working on spring cloud project using spring boot. Our goal is to create an executable war that can be run using java -jar .

I followed couple of posts on SO and was able to generate the executable war by 1) adding "boot" classifier tag in . 2) Adding Repackage goal in execution phase for spring-boot-maven-plugin

Now with this approach I'm getting two war files : one war that is not executable but just deployable and another war with boot classifier that suits my requirements

Is there a way to just generate only the executable war?

I'm attaching the pom.xml for easy reference

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>
            **<configuration>
                <classifier>boot</classifier>
            </configuration>
            <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>
                <outputDirectory>target</outputDirectory>
                <warName>ROOT</warName>
            </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>

References: One Spring Boot project, deploy to both JAR or WAR

Failed to load Main-Class manifest attribute while running java -jar

4
  • 1
    You don't need to add any kind of classifier. The one that Spring Boot produces works as java -jar and deployed in a servlet container. Have you tried? Commented Oct 27, 2016 at 16:28
  • @Stephane Thanks for your comment, the war that spring boot produces can be deployed on a servlet container and we did not want to do that. So we need an executable war that can be run using java -jar command. I have done my part of research before posting this question here Commented Oct 27, 2016 at 19:00
  • To be more clear, we just want to use embedded tomcat server without deploying on external servlet container Commented Oct 27, 2016 at 19:11
  • 2
    I understood your question and I am asking whether you tried or not because that's what's happening by default if you use the repackage goal. Head over start.spring.io, click advanced, choose war packaging, click generate project. Unzip the project, invoke mvn package then java -jar target/demo-0.0.1-SNAPSHOT.war and your application will start. Commented Oct 27, 2016 at 19:39

1 Answer 1

4

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

My original problem was I was getting two war files in the target:

  1. Root.war and the other
  2. discovery-service-boot.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.

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

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


    <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>
</project>
Sign up to request clarification or add additional context in comments.

1 Comment

Some info repackage goal in spring boot maven plugin and also the consequence of using a classifier. docs.spring.io/spring-boot/docs/current/maven-plugin/examples/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.