0

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>
Anas Tina
  • 329
  • 1
  • 2
  • 14

1 Answers1

1

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>
Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
  • Hi, I followed your solution but I got the following message when I run the jar "no main manifest attribute, in EAB.ActiveTeam.Exporter-1.0-SNAPSHOT.jar" – Anas Tina Dec 01 '19 at 05:53
  • have you removed all other plugins from pom? open the jar with WinRar and check what's inside – Mark Bramnik Dec 01 '19 at 05:58
  • META-INF/MANIFEST.MF META-INF/ EAB/ EAB/ActiveTeam/ EAB/ActiveTeam/Exporter/ META-INF/maven/ META-INF/maven/EAB.ActiveTeam.Exporter/ META-INF/maven/EAB.ActiveTeam.Exporter/EAB.ActiveTeam.Exporter/ EAB/ActiveTeam/Exporter/App.class EAB/ActiveTeam/Exporter/CustomerItemProcessor.class META-INF/maven/EAB.ActiveTeam.Exporter/EAB.ActiveTeam.Exporter/pom.properties META-INF/maven/EAB.ActiveTeam.Exporter/EAB.ActiveTeam.Exporter/pom.xml EAB/ActiveTeam/Exporter/BatchConfiguration$1$1.class EAB/ActiveTeam/Exporter/BatchConfiguration.class EAB/ActiveTeam/Exporter/BatchConfiguration$1.class – Anas Tina Dec 01 '19 at 06:09
  • the above is the jar contents – Anas Tina Dec 01 '19 at 06:10
  • Manifest-Version: 1.0 Created-By: Apache Maven 3.6.1 Built-By: Administrator Build-Jdk: 11.0.3 – Anas Tina Dec 01 '19 at 06:11
  • The above is the content of Manifest.MF – Anas Tina Dec 01 '19 at 06:12
  • Try generating spring boot app from start.spring.io and check the pom.xml that it has, find the differences with yours and see what's wrong, I'm sure about the reason, but without seeing the actual pom its hard to reason. I see from your comments that `. no boot-inf lib folder => dependencie are not picked, this is wrong. 2. Manifest mf is wrong (again compare with the one generated by start.spring.io) – Mark Bramnik Dec 01 '19 at 06:31
  • [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin :2.2.1.RELEASE:repackage (repackage) on project EAB.ActiveTeam.Exporter: Unable to parse configuration of mojo org.springframework.boot:spring-boot-maven-plugin :2.2.1.RELEASE:repackage: Cannot convert 'jar' to Enum: No enum constant org.spr ingframework.boot.maven.RepackageMojo.LayoutType.jar -> [Help 1] – Anas Tina Dec 01 '19 at 06:53
  • You've configured the spring-boot-maven-plugin wrong this time – Mark Bramnik Dec 01 '19 at 06:55
  • post your pom.xml as it looks now in the question – Mark Bramnik Dec 01 '19 at 06:56
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/203413/discussion-between-anas-tina-and-mark-bramnik). – Anas Tina Dec 01 '19 at 06:58