xxx.jar 中没有主要清单属性 [maven- assembly-plugin 不起作用]

Kha*_*led 5 java pom.xml

我的 pom.xml 中有 maven-assemble-plugin:

        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>com.xxx.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-my-jar-with-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
Run Code Online (Sandbox Code Playgroud)

因此,在构建项目后,我得到了 xxx-1.0-SNAPSHOT.jar 可执行文件。因此,当我在终端中运行它时,例如:

$ java -jar xxx.jar
Run Code Online (Sandbox Code Playgroud)

它返回:

no main manifest attribute, in xxx-1.0-SNAPSHOT.jar
Run Code Online (Sandbox Code Playgroud)

JF *_*ier 10

您的构建会创建一个额外的 jar,jar-with-dependencies其名称中包含该 jar。你必须运行这个罐子。