Home  >  Forum  >  Spring
Post New Query

Spring Boot: How to create executable JAR



Asked on March 17, 2017
I am a beginner for spring boot. Please reply how to create executable JAR using spring boot?



Replied on March 17, 2017
Find the steps to create executable JAR.

Step 1:
 Make sure your pom.xml should contain.

   a. <packaging>jar</packaging>

   b.
         <plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>


Step 2.   Run command: mvn clean package

Step 3:  Suppose we have a pom.xml for web project as follows.

<?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.concretepage</groupId>
<artifactId>spring-boot-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-demo</name>
<description>Spring Boot Demo Project</description>
<parent>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-parent</artifactId>
   <version>1.5.2.RELEASE</version>
</parent>
<properties>
   <java.version>1.8</java.version>
</properties>
<dependencies>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
         <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-devtools</artifactId>
                    <optional>true</optional>
            </dependency> 
</dependencies> 
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project> 

Step 4: Within the folder target, we have two JAR

        spring-boot-demo-0.0.1-SNAPSHOT.jar   : This is executable JAR
        spring-boot-demo-0.0.1-SNAPSHOT.jar.original  : This is original JAR and not executable.

Step 5: Run executable JAR as follows

    java -jar target/spring-boot-demo-0.0.1-SNAPSHOT.jar


Tomcat server will be started and we are ready to test our application.
     





Write Answer








©2019 concretepage.com | Privacy Policy | Contact Us