SpringBoot没有主清单属性(Maven)

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)


tma*_*wen 9

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目标的更多详细信息。


Mat*_*tej 7

尝试将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)

  • 如果你的 pom 中有 `spring-boot-starter-parent` ,则不需要在插件中定义 `repackage` 目标。官方文档:https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/maven-plugin/reference/html/#repackage (7认同)
  • 它有帮助!你能解释为什么我需要打包吗? (2认同)
  • 原因是你没有使用 spring 作为父级,我假设你已经在 dependencyManagement 上设置了它,那么你必须显式定义要为 spring-boot-maven-plugin 挂钩的目标以获得可执行的 jar 文件。在这种情况下重新包装。 (2认同)

小智 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。