Can't execute jar- file: “no main manifest attribute”

后端 未结 30 1944
不知归路
不知归路 2020-11-21 22:30

I have installed an application, when I try to run it (it\'s an executable jar) nothing happens. When I run it from the commandline with:

java -jar \

相关标签:
30条回答
  • 2020-11-21 22:55

    You Can Simply follow this step Create a jar file using

     jar -cfm jarfile-name manifest-filename Class-file name
    

    While running the jar file simple run like this

     java -cp jarfile-name main-classname
    
    0 讨论(0)
  • 2020-11-21 22:56

    Alternatively, you can use maven-assembly-plugin, as shown in the below example:

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>com.package.MainClass</mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin> 
    

    In this example all the dependency jars as specified in section will be automatically included in your single jar. Note that jar-with-dependencies should be literally put as, not to be replaced with the jar file names you want to include.

    0 讨论(0)
  • 2020-11-21 22:57

    I had this problem and i solved it recently by doing this in Netbeans 8 (Refer to the image below):

    Netbeans project properties

    1. go to properties of your project.
    2. click on Run.
    3. specify the main class of your project using browse.
    4. build and run the Jar file.
    0 讨论(0)
  • 2020-11-21 22:58

    I got same error just now. If u're using gradle, just add next one in ur gradle.build:

    apply plugin: 'java'
    
    jar {
        manifest {
            attributes 'Main-Class': 'com.company.project.MainClass'
        }
    }
    

    Where com.company.project.MainClass path to ur class with public static void main(String[] args) method.

    0 讨论(0)
  • 2020-11-21 23:00

    I had this issue when creating a jar using IntelliJ IDEA. See this discussion.

    What solved it for me was to re-create the jar artifact, choosing JAR > From modules with dependencies, but not accepting the default Directory for META-INF/MANIFEST.MF. Change it from -/src/main/java to -/src/main/resources.

    Otherwise it was including a manifest file in the jar, but not the one in -/src/main/java that it should have.

    0 讨论(0)
  • 2020-11-21 23:02

    Try this command to include the jar:

    java -cp yourJarName.jar your.package..your.MainClass
    
    0 讨论(0)
提交回复
热议问题