Reputation: 339
I am trying to run an executable jar but got the following message :
Could not find or load main class
Here is the content of MANIFEST.MF file:
Manifest-Version: 1.0
Created-By: Apache Maven Built-By: Administrator
Build-Jdk: 11.0.3
Class-Path: spring-boot-starter-batch-2.2.0.RELEASE.jar spring-boot-starter-1.5.6.RELEASE.jar spring-boot-1.5.6.RELEASE.jar spring-boot-autocon
figure-1.5.6.RELEASE.jar .......
Main-Class: EAB.ActiveTeam.Exporter.App
I am really stuck as I searched the web, tried many solutions to make my executable JAR run!
Please help, I sent over 5 hours trying to fix with no luck!
here is my POM.xml file:
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>EAB.ActiveTeam.Exporter</groupId>
<artifactId>EAB.ActiveTeam.Exporter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>EAB.ActiveTeam.Exporter</name>
<description>EAB.ActiveTeam.Exporter</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>EAB.ActiveTeam.Exporter.App</mainClass>
<layout>jar</layout>
<outputDirectory>../libs</outputDirectory>
</configuration>
<executions>
<execution>
<id>repackage</id>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Upvotes: 0
Views: 1644
Reputation: 42491
When it comes to spring boot application you can't create a regular jar file, because spring boot application jar is not a jar at all. It doesn't have an internal directory layout of jar (all dependencies are in BOOT-INF/lib for example) and there are some other subtle differences.
So I believe the issue is with maven here.
Instead of trying to create jar "by youself" and add all the dependencies there you should use spring boot maven plugin:
It "knows" how to create a spring boot jar properly.
By default it will also resolve your "main" file (the one with method main
and @SpringBootApplication
annotation) however you can specify it in plugin configuration to be on the safe side.
Then you'll be able to the project with :
java -jar <Name_of_your_jar>
Upvotes: 1