17 June, 2019

No main manifest attribute, in sample-hello-microservice-springboot.jar

The error "no main manifest attribute, in sample-hello-microservice-springboot.jar" occurred while trying to execute the jar file. This is very unusual issue with jar file execution. In this case I was trying to run the docker image. The reason of this issue, during the jar execution it was not able to locate the main class. Below is the main class "HelloApplication" and pom file. It seems the spring-boot plugin was missing with config for the manifest (mainClass). 

HelloApplication.java


package com.javadevelopersguide.lab.springboot.application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.javadevelopersguide.springboot.business.DeliverHello;
@SpringBootApplication
@EnableAutoConfiguration
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(DeliverHello.class);
}
}

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 Springboot.</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<!-- Setup Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<!-- Setup Spring MVC & REST, use Embedded Tomcat -->
<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>
</plugins>
</build>
</project>

Solution :-

 I have added the manifest in the pom.xml 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/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 Springboot.</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<!-- Setup Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<!-- Setup Spring MVC & REST, use Embedded Tomcat -->
<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.javadevelopersguide.lab.springboot.application.HelloApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Now its working fine. You can see the below screenshot to see the result.




Checking on browser.













No comments:

Post a Comment