Showing posts with label Spring Boot Error. Show all posts
Showing posts with label Spring Boot Error. Show all posts

Monday, June 17, 2019

Spring Boot JAR Error: No Main Manifest Attribute

The error "no main manifest attribute, in sample-hello-microservice-springboot.jar" occurred while trying to execute the JAR file.

This was an unusual issue with JAR file execution. In this case, I was trying to run the Docker image. The reason for this issue was that, during JAR execution, it was not able to locate the main class.

Below is the main class, HelloApplication, and the pom.xml file. It seems that the Spring Boot Maven plugin was missing, along with the configuration for the manifest (mainClass).

HelloApplication.java

package com.techbyteslearn.lab.springboot.application;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HelloApplication {

    public static void main(String[] args) {
        SpringApplication.run(HelloApplication.class, args);
    }
}

pom.xml

<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>sample-hello-microservice-springboot</groupId> <artifactId>sample-hello-microservice-springboot</artifactId> <version>0.0.1-SNAPSHOT</version> <description>Sample Hello microservice with Spring Boot.</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> </parent> <dependencies> <!-- Setup Spring Boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <!-- Setup Spring MVC & REST with Embedded Tomcat --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <archive> <manifest> <mainClass> com.techbyteslearn.lab.springboot.application.HelloApplication </mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> </project>

Solution:

I added the Spring Boot Maven plugin and configured the main class in the pom.xml file.

After making this change, the JAR was created with the required manifest information, and the application started working fine when the JAR was executed.

You can see the screenshot below to see the result.






Checking on browser.












Hope this will help you.