[英]Error: Could not find or load main class Maven Spring Boot Application - Executable JAR
I am trying to run an executable jar but got the following message :我正在尝试运行一个可执行的 jar,但收到以下消息:
Could not find or load main class
Here is the content of MANIFEST.MF file:下面是 MANIFEST.MF 文件的内容:
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!当我在网上搜索时,我真的被困住了,尝试了很多解决方案来让我的可执行 JAR 运行!
Please help, I sent over 5 hours trying to fix with no luck!请帮忙,我发送了 5 多个小时试图修复但没有运气!
here is my POM.xml file:这是我的 POM.xml 文件:
<?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>
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.对于 spring boot 应用程序,您无法创建常规 jar 文件,因为 spring boot 应用程序 jar 根本不是 jar。 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.它没有 jar 的内部目录布局(例如,所有依赖项都在 BOOT-INF/lib 中)并且还有一些其他细微的差异。
So I believe the issue is with maven here.所以我相信问题出在 maven 上。
Instead of trying to create jar "by youself" and add all the dependencies there you should use spring boot maven plugin :与其尝试“自己”创建 jar 并在其中添加所有依赖项,不如使用spring boot maven 插件:
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.默认情况下,它还将解析您的“主”文件(带有方法main
和@SpringBootApplication
注释的文件),但是您可以在插件配置中指定它以确保安全。
Then you'll be able to the project with :然后,您将能够使用以下项目进行项目:
java -jar <Name_of_your_jar>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.