Spring Maven boot module not creating executable jar

My POM looks like this. But the executable JAR is not created when I run "mvn clean package". However, when I remove the dependencyManagement element and add spring boot as the parent POM everything works.

What am I missing?

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

      

+3


source to share


7 replies


You need to configure the spring-boot-maven-plugin yourself:

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

      



Obviously install your own version of the plugin. Now if you run mvn install or mvn package, you will get an executable JAR.

+19


source


This is because the plugin is configured by the parent in the second case. If you want to manage your own plugins (i.e. not use the parent), you need to explicitly configure the spring boot plugin (and others).



+2


source


When using Spring Boot Management (no spring-boot-starter-parent), you can still keep dependency management but not plugin management .

This means you need to provide the complete plugin (with version and other stuff).

+1


source


Spring Boot so that your application will load as a test on startup mvn package

. Make sure it doesn't happen during this.

+1


source


It sets the pom.xml , to create an executable jar file

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

      

To create an executable jar, enter the following command

$ mvn clean
$ mvn install

      

Watch the video: https://youtu.be/Yy8RxjdcTfE

0


source


According to the SpringBoot doc. The plugin overwrites your manifest and specifically manages the Main-Class and Start-Class entries, so if the defaults don't work, you need to configure them (not in the plugin jar). The main class in the manifest is actually controlled by the layout property of the load module

SpringBoot Maven-plugin-not-create-executable-jar

Below is the change as per the SpringBoot docs for me.

    <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


source


I have been building a runnable JAR (Maven POM) for a project for over a year and recently something changed and the JAR no longer contained the JAR dependencies. In the end, fixing the latest version of Spring (1.5.2.RELEASE for me at the time of writing) resolved the problem.

0


source







All Articles