spring-boot Maven: How to create executable jar with main class?

CrazySynthax :

Recently, I wrote a Spring-Boot project and I wanted that Maven will be able to create a jar file that I'll be able to run by the command "java -jar ".

This is the pom.xml I wrote:

<?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>SpringBootGame</groupId>
    <artifactId>SpringBootGame</artifactId>
    <version>1.0-SNAPSHOT</version>

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

    <properties>
        <java.version>1.8</java.version>
    </properties>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.0.3.RELEASE</version>
                <configuration>
                    <mainClass>com.game.Main</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

In order to build the jar file, I had to run the command: "mvn clean package spring-boot:repackage".

My questions are:

  1. Why must I add spring-boot-maven-plugin? I already have spring-boot-starter-web dependency that adds spring-boot as a dependency and maven-compiler-plugin that builds a jar file from the code?

  2. Can you think about a way to configure pom.xml file that I'll be able to get the jar file using the "native" command "mvn clean package" and not the cumbersome "mvn clean package spring-boot:repackage"?

Thanks

Edwin Diaz :

Why must I add spring-boot-maven-plugin? I already have spring-boot-starter-web dependency that adds spring-boot as a dependency and maven-compiler-plugin that builds a jar file from the code?

Because the plugin is what adds Maven support for Spring Boot

Can you think about a way to configure pom.xml file that I'll be able to get the jar file using the "native" command "mvn clean package" and not the cumbersome "mvn clean package spring-boot:repackage"?

It looks like you are missing the <packaging>jar</packaging> element in between your <project> </project> element.

The reason you had to run that lengthy command, is because you did not include the <executions></executions> element when including the plugin. Please see section 71.1 of the following docs:

https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html#build-tool-plugins-include-maven-plugin

71.2 elaborates on the <packaging> element.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Error: Could not find or load main class Maven Spring Boot Application - Executable JAR

From Dev

Launching main class inside a nested executable jar created with spring-boot-maven-plugin

From Dev

IntelliJ Spring Boot: How to create an executable jar

From Dev

How to create executable jar in Kotlin using maven-assembly-plugin without a main class?

From Dev

How do I create an executable jar file including dependencies where the main class is in Test, using Maven

From Java

How do I tell Spring Boot which main class to use for the executable jar?

From Java

How to create spring-based executable jar with maven?

From Dev

Create executable jar file in Spring Boot

From Dev

how does maven-spring-boot-plugin determine the main class?

From Java

Spring Boot + Gradle: how to build executable jar

From Dev

how to understand spring boot about executable jar

From Java

Create Jar of maven spring boot project

From Dev

cmake for Java, how to specify main class and make jar file executable?

From Java

Spring Boot Executable Jar with Classpath

From Dev

Spring boot executable jar on openshift

From Dev

Executable Spring Boot 2 jar

From Dev

Maven create Spring Boot jar and plain jar with specific classes

From Java

How can I create an executable jar without dependencies using Maven?

From Java

How can I create an executable JAR with dependencies using Maven?

From Dev

How can I create an executable/runnable JAR with dependencies using Maven?

From Dev

How to create a executable jar file using Maven and Netbeans

From Dev

How to create executable jar file from springboot - maven application?

From Dev

How to package React front end with Spring Boot and run the executable jar?

From Java

How to start executable spring boot jar file with external *.ampl on Linux?

From Java

Resource is not loading in executable Spring boot jar - How executable jar loads resources?

From Java

Error: Could not find or load main class - Spring Boot Application jar

From Java

Running executable jar created by maven-assembly: Error: Could not find or load main class

From Dev

executable jar for selenium testng maven project which dont have a main class

From Java

How to create/find application jar to deploy your spring boot maven application using embedded tomcat?

Related Related

  1. 1

    Error: Could not find or load main class Maven Spring Boot Application - Executable JAR

  2. 2

    Launching main class inside a nested executable jar created with spring-boot-maven-plugin

  3. 3

    IntelliJ Spring Boot: How to create an executable jar

  4. 4

    How to create executable jar in Kotlin using maven-assembly-plugin without a main class?

  5. 5

    How do I create an executable jar file including dependencies where the main class is in Test, using Maven

  6. 6

    How do I tell Spring Boot which main class to use for the executable jar?

  7. 7

    How to create spring-based executable jar with maven?

  8. 8

    Create executable jar file in Spring Boot

  9. 9

    how does maven-spring-boot-plugin determine the main class?

  10. 10

    Spring Boot + Gradle: how to build executable jar

  11. 11

    how to understand spring boot about executable jar

  12. 12

    Create Jar of maven spring boot project

  13. 13

    cmake for Java, how to specify main class and make jar file executable?

  14. 14

    Spring Boot Executable Jar with Classpath

  15. 15

    Spring boot executable jar on openshift

  16. 16

    Executable Spring Boot 2 jar

  17. 17

    Maven create Spring Boot jar and plain jar with specific classes

  18. 18

    How can I create an executable jar without dependencies using Maven?

  19. 19

    How can I create an executable JAR with dependencies using Maven?

  20. 20

    How can I create an executable/runnable JAR with dependencies using Maven?

  21. 21

    How to create a executable jar file using Maven and Netbeans

  22. 22

    How to create executable jar file from springboot - maven application?

  23. 23

    How to package React front end with Spring Boot and run the executable jar?

  24. 24

    How to start executable spring boot jar file with external *.ampl on Linux?

  25. 25

    Resource is not loading in executable Spring boot jar - How executable jar loads resources?

  26. 26

    Error: Could not find or load main class - Spring Boot Application jar

  27. 27

    Running executable jar created by maven-assembly: Error: Could not find or load main class

  28. 28

    executable jar for selenium testng maven project which dont have a main class

  29. 29

    How to create/find application jar to deploy your spring boot maven application using embedded tomcat?

HotTag

Archive