我已经安装了一个应用程序,当我试图运行它(它是一个可执行的jar)什么都没有发生。当我从命令行运行它时:

Java -jar "app.jar"

我得到了以下信息:

在“app.jar”中没有主清单属性

通常,如果我自己创建了这个程序,我就会向清单文件添加一个主类属性。但在这种情况下,由于文件来自应用程序,我不能这样做。我还尝试提取jar,看看是否能找到主类,但有很多类,没有一个在它的名称中有“main”这个词。必须有一种方法来修复这个问题,因为程序在其他系统上运行良好。


当前回答

我和你有相似的问题, 在下面的语法中成功创建。war文件:-

Jar {cvf} [Jar -file] [manifest-file]

清单 当创建(c)或更新(u) JAR文件时,manifest操作数用要包含在manifest中的属性的名称和值定义先前存在的清单文件。MF在JAR文件中。如果f选项'[1]'存在,则必须指定清单操作数。

为了创建清单文件,你需要为某些属性定义一个值,你可以在(.WAR)文件名后面加上星号,以避免创建清单文件:-

罐子 -cvf foo.war *

老实说,我不知道这是否是一个最好的做法,但它为我工作:)。

其他回答

如果jar不遵守规则,它就不是一个可执行的jar。

我和你有相似的问题, 在下面的语法中成功创建。war文件:-

Jar {cvf} [Jar -file] [manifest-file]

清单 当创建(c)或更新(u) JAR文件时,manifest操作数用要包含在manifest中的属性的名称和值定义先前存在的清单文件。MF在JAR文件中。如果f选项'[1]'存在,则必须指定清单操作数。

为了创建清单文件,你需要为某些属性定义一个值,你可以在(.WAR)文件名后面加上星号,以避免创建清单文件:-

罐子 -cvf foo.war *

老实说,我不知道这是否是一个最好的做法,但它为我工作:)。

以我为例——我从事的是一个多模块项目——我可以用以下方式介绍这个问题:

我将其添加到父文件pom.xml中,这导致了问题。即,值为true的skip:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <!--
                besides hindering the packaging, this also skips running the app after build when calling spring-boot:run. You have to enable it in the
                corresponding module by setting skip to false, there.
                -->
                <skip>true</skip>
            </configuration>
        </plugin>
    </plugins>
</build>

我修复了这个问题,通过添加相同的配置到模块,我想打包成一个jar,但改变了跳过的值为false:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${spring-boot.version}</version>
    <configuration>
        <mainClass>${project.mainClass}</mainClass>
        <layout>ZIP</layout>
        <skip>false</skip>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
        <execution>
            <id>build-info</id>
            <goals>
                <goal>build-info</goal>
            </goals>
        </execution>
    </executions>
</plugin>

如果使用Maven,请在pom中包含以下内容

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
</parent>

<properties>
    <java.version>1.8</java.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Gradle的答案是添加一个jar/manifest/attributes设置,像这样:

apply plugin: 'java'

jar {
    manifest {
        attributes 'Main-Class': 'com.package.app.Class'
    }
}