【问题标题】:no main manifest attribute maven build even after adding class path and main class即使在添加类路径和主类之后也没有主清单属性 maven 构建
【发布时间】:2020-02-26 09:14:30
【问题描述】:

在 jaspr2-0.0.1-SNAPSHOT.jar 中运行应用程序 jar no main manifest 属性时遇到错误。

在所有答案中,我发现应该提到添加类路径和主类。在我的 POM 中,我提到了两者。在构建之后,我发现 Manifest 文件没有附加主类,并且 Boot/INF 也没有添加到 jar 中。寻找构建适当 jar 的解决方案。下面是我的 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.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.abn</groupId>
    <artifactId>jaspr2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>jaspr2</name>
    <description>Project for jcl validation</description>

    <properties>
        <java.version>1.8</java.version>
        <antlr.version>4.8-1</antlr.version>
        <targetDirectory>target</targetDirectory>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> 
            <scope>runtime</scope> </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>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
            <version>7.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-core</artifactId>
            <version>7.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-decisiontables</artifactId>
            <version>7.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-runtime</artifactId>
            <version>${antlr.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.antlr/antlr4-maven-plugin -->
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-maven-plugin</artifactId>
            <version>${antlr.version}</version>
        </dependency>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4</artifactId>
            <version>${antlr.version}</version>
        </dependency>
        <dependency>
            <groupId>org.antlr</groupId>
            <artifactId>antlr4-master</artifactId>
            <version>${antlr.version}</version>
            <type>pom</type>
        </dependency>
    </dependencies>
    <build>
        <!-- <finalName>jaspr-application</finalName> -->
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.antlr</groupId>
                    <artifactId>antlr4-maven-plugin</artifactId>
                    <version>${antlr.version}</version>
                    <configuration>
                        <sourceDirectory>${basedir}/src</sourceDirectory>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>antlr4</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>${mojo.version}</version>
                    <executions>
                        <execution>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>add-source</goal>
                            </goals>
                            <configuration>
                                <sources>
                                    <source>${basedir}/src/main/java/com/abn/jaspr/antlr/generated</source>
                                </sources>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <mainClass>com.abn.jaspr.Jaspr2Application</mainClass>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version>
                    <configuration>
                        <jvmArguments>-Dfile.encoding=UTF8</jvmArguments>
                        <source>1.8</source>
                        <target>1.8</target>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

</project>

【问题讨论】:

  • 能否告诉我们用于构建 jar 的 maven 命令?
  • maven clean 和 maven install using eclipse

标签: java maven build maven-plugin spring-boot-maven-plugin


【解决方案1】:

对于 Spring Boot,您可以使用属性中的 start 类定义主类。

以下是您更新后的属性

<properties>
    <java.version>1.8</java.version>
    <antlr.version>4.8-1</antlr.version>
    <targetDirectory>target</targetDirectory>
    <start-class>com.abn.jaspr.Jaspr2Application</start-class>
</properties>

希望对你有帮助

【讨论】:

  • 我试过更新插件,如你所说。仍然发现同样的问题。
  • 你尝试过 maven-jar-plugin 并添加 start-class 属性吗?
  • 是的,我都添加了。我观察到的是没有打包依赖jar,也没有添加bootinf
  • 仅添加 start-class 属性就足以让 Spring Boot 更新清单中的 Main-Class。我尝试使用您使用的 POM 插件,它对我有用。
  • 对我来说,它也适用于具有相同插件的不同项目。对于这个特定项目,依赖项和 sprig boot inf 未添加到 jar 中。无法确定实际问题。
【解决方案2】:

由于插件管理中的 spring-boot-maven-plugin 没有执行并添加 spring boot INF 文件夹。 刚刚将 spring-boot-maven-plugin 移到插件管理标签之外,它就解决了这个问题。

从其他问题的这个答案中找到更多详细信息 Spring Boot Maven Plugin not creating executable jar

【讨论】:

    猜你喜欢
    • 2019-10-17
    • 2019-07-19
    • 1970-01-01
    • 2015-02-01
    • 2019-08-04
    • 2013-12-15
    • 2013-03-13
    • 1970-01-01
    • 2019-09-14
    相关资源
    最近更新 更多