Jey*_*eyJ 7 java manifest maven spring-boot spring-boot-maven-plugin
运行我的jar文件时:java -jar target / places-1.0-SNAPSHOT.jar我遇到下一个错误:
no main manifest attribute, in target/places-1.0-SNAPSHOT.jar
Run Code Online (Sandbox Code Playgroud)
我的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>
Run Code Online (Sandbox Code Playgroud)
我也试图创建一个MANIFEST.MF文件并指定该类,但是它没有帮助。
另外,我还尝试了:
<properties>
<!-- The main class to start by executing "java -jar" -->
<start-class>com.places.Main</start-class>
</properties>
Run Code Online (Sandbox Code Playgroud)
我的主要:
@SpringBootApplication
public class Main {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(Main.class,args);
}
}
Run Code Online (Sandbox Code Playgroud)
你知道我还能尝试什么吗?
Mat*_*ttC 16
3 件事:
- 您的 pom.xml 文件中有父条目。
- 验证您的插件是否在 pom 的构建部分。
- 您有一个带有 @SpringBootApplicaion 注释的类。
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>
...
Run Code Online (Sandbox Code Playgroud)
还有一个看起来像这样的类:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
在Maven package阶段,Spring Boot Maven插件增强了jar存档,原始的jar文件(应该使用标准的maven-jar-plugin构建了该文件)被增强的可执行 jar 所代替。
因此,spring-boot:repackage在构建模块时,您必须自己发布目标:
mvn package spring-boot:repackage
Run Code Online (Sandbox Code Playgroud)
或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>
Run Code Online (Sandbox Code Playgroud)
您可以在官方文档中找到有关Spring Boot Maven插件 repackage目标的更多详细信息。
尝试将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>
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以指定父POM,例如:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
</parent>
Run Code Online (Sandbox Code Playgroud)
在打包目标期间,将执行重新打包目标,然后您将获得一个可执行的 jar。
| 归档时间: |
|
| 查看次数: |
5680 次 |
| 最近记录: |