Java SpringBoot 没有主要清单属性(maven)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54867295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SpringBoot no main manifest attribute (maven)
提问by JeyJ
When running my jar file : java -jar target/places-1.0-SNAPSHOT.jar I'm getting the next error :
运行我的 jar 文件时:java -jar target/places-1.0-SNAPSHOT.jar 我收到下一个错误:
no main manifest attribute, in target/places-1.0-SNAPSHOT.jar
My pom.xml contains the spring-boot-maven-plugin :
我的 pom.xml 包含 spring-boot-maven-plugin :
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.places.Main</mainClass>
</configuration>
</plugin>
I also tried to create a MANIFEST.MF FILE and specifying the class but it didnt help.
我还尝试创建一个 MANIFEST.MF 文件并指定类,但没有帮助。
In addition, I also tried :
此外,我还尝试过:
<properties>
<!-- The main class to start by executing "java -jar" -->
<start-class>com.places.Main</start-class>
</properties>
My main :
我的主要:
@SpringBootApplication
public class Main {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(Main.class,args);
}
}
any idea what else can I try ?
知道我还能尝试什么吗?
采纳答案by Matej
Try adding repackage
goal to execution goals. Otherwise you would need to call the plugin explicitly as mvn package spring-boot:repackage
. With the goal added, you have to call only mvn package
.
尝试将repackage
目标添加到执行目标。否则,您需要将插件显式调用为mvn package spring-boot:repackage
. 添加目标后,您只需调用mvn package
.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.places.Main</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
回答by tmarwen
During the Mavenpackage
lifecycle phase, the jararchive is enhanced by Spring Boot Maven Pluginand the original jarfile (that should have been built using the standard maven-jar-plugin) is replaced with an enhancedexecutablejar.
在Mavenpackage
生命周期阶段,Spring Boot Maven 插件增强了jar存档,并且原始jar文件(应该使用标准maven-jar-plugin构建)替换为增强的可执行jar。
Hence you have either to issue the spring-boot:repackage
goal yourself when building your module:
因此,您必须spring-boot:repackage
在构建模块时自己发布目标:
mvn package spring-boot:repackage
Or add the goal
explicitly within the plugin configuration:
或者goal
在插件配置中显式添加:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.places.Main</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
You can find more details about the Spring Boot Maven Pluginrepackage
goalwithin the official documentation.
您可以在官方文档中找到有关Spring Boot Maven 插件repackage
目标的更多详细信息。
回答by laurentJ
You can specify a parent POM eg :
您可以指定父 POM,例如:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
</parent>
During the package goal, the repackage goal will be executed and you'll then get an executable jar
在打包目标期间,将执行重新打包目标,然后您将获得一个可执行的 jar
回答by MattC
3 things:
- You have the parent entry in your pom.
- Verify that your plugin is in the build portion of the pom.
- You have a class with the @SpringBootApplicaion annotation.
3 件事:
- 您的 pom.xml 文件中有父条目。
- 验证您的插件是否在 pom 的构建部分。
- 您有一个带有 @SpringBootApplicaion 注释的类。
pom.xml:
pom.xml:
...
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
...
And a class that looks something like this:
还有一个看起来像这样的类:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}