Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring boot application is not creating fat (uber) jar

I'm following the example here: https://www.baeldung.com/spring-boot-start

When I build the app, I'm not getting the fat jar with all the dependencies, but only a jar with the compiled classes of the project.

I paste the pom.xml below.

<?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>org.baeldung</groupId>
    <artifactId>spring-boot-bootstrap</artifactId>
    <packaging>jar</packaging>
    <name>spring-boot-bootstrap</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <artifactId>parent-boot-2</artifactId>
        <groupId>com.baeldung</groupId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../parent-boot-2</relativePath>
    </parent>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cloud-connectors</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>${rest-assured.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlet.version}</version>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>cloud-gcp</id>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-gcp-starter</artifactId>
                    <version>1.0.0.RELEASE</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-gcp-starter-sql-mysql</artifactId>
                    <version>1.0.0.RELEASE</version>
                </dependency>
            </dependencies>
            <build>
                <finalName>${project.name}-gcp</finalName>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <excludes>
                            <exclude>**/logback.xml</exclude>
                        </excludes>
                    </resource>
                </resources>
                <plugins>
                    <plugin>
                        <groupId>com.google.cloud.tools</groupId>
                        <artifactId>appengine-maven-plugin</artifactId>
                        <version>1.3.2</version>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>cloudfoundry</id>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-starter</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-cloud-connectors</artifactId>
                </dependency>
            </dependencies>
            <build>
                <finalName>${project.name}-cf</finalName>
                <resources>
                    <resource>
                        <directory>src/main/resources</directory>
                        <excludes>
                            <exclude>**/logback.xml</exclude>
                        </excludes>
                    </resource>
                </resources>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <excludes>
                                <exclude>**/cloud/config/*.java</exclude>
                            </excludes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>autoconfiguration</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>integration-test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                    <excludes>
                                        <exclude>**/*LiveTest.java</exclude>
                                        <exclude>**/*IntegrationTest.java</exclude>
                                        <exclude>**/*IntTest.java</exclude>
                                    </excludes>
                                    <includes>
                                        <include>**/AutoconfigurationTest.java</include>
                                    </includes>
                                </configuration>
                            </execution>
                        </executions>
                        <configuration>
                            <systemPropertyVariables>
                                <test.mime>json</test.mime>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>thin-jar</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot.experimental</groupId>
                        <artifactId>spring-boot-thin-maven-plugin</artifactId>
                        <version>${thin.version}</version>
                        <executions>
                            <execution>
                                <!-- Download the dependencies at build time -->
                                <id>resolve</id>
                                <goals>
                                    <goal>resolve</goal>
                                </goals>
                                <inherited>false</inherited>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/cloud/*.java</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <servlet.version>4.0.0</servlet.version>
    </properties>

</project>
like image 809
Andres Avatar asked Oct 10 '18 23:10

Andres


People also ask

What is uber jar in Spring Boot?

In this tutorial, we will be discussing about the Uber JAR creation of a spring boot project. The Uber JAR is a JAR where all of the application's compiled code along with the dependencies are grouped together so, that the programmer may find easy if he needs to deploy it somewhere as the dependencies come along with the JAR.

What is fat jar builder in Spring Boot?

It automates building a sample Java project as Fat (or so-called Uber) Jar to run it as a microservice. To get started, log in to Jelastic dashboard, find the Spring Boot Fat Jar Builder in the Marketplace and click Install.

Does Spring Boot support single jar files?

Alternative Single Jar Solutions The spring-boot-loader modules lets Spring Boot support executable jar and war files. If you use the Maven plugin or the Gradle plugin, executable jars are automatically generated, and you generally do not need to know the details of how they work.

What is the use of Spring Boot-Loader?

The spring-boot-loader modules lets Spring Boot support executable jar and war files. If you use the Maven plugin or the Gradle plugin, executable jars are automatically generated, and you generally do not need to know the details of how they work.


1 Answers

This made the job:

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <mainClass>
                            com.domain.Application
                        </mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
like image 176
Andres Avatar answered Oct 10 '22 12:10

Andres