简体   繁体   中英

Java JAR: Could not find or load main class

I know this question has been asked a lot, but I have tried a few suggestions and am still getting this error.

I am running the jar as follows:

java -jar MyJar-1.0.jar com.me.ldap.ActiveMain ,

where my ActiveMain.java file looks like this:

package com.me.ldap;

public class ActiveMain {
    public static void main(String[] args) throws Exception {
    ...
    }
} 

I have also tried simply java -jar MyJar-1.0.jar with the same Error: Could not find or load main class error. I've also looked into the class path option but I don't think that applies.

I am creating it in Intellij as a Maven project. Maven > Lifecycle > package .

In order for:

java -jar myfile.jar

to work, there must be a manifest file in the jar file that points to a main class.

In order for you to specify the main class on the command line, you need to specify a classpath, not a jar file. Like:

java -cp myfile.jar com.me.ldap.ActiveMain

You are conflating these two things. Either create a manifest that specifies your main class and use the -jar switch, or simply use the -cp switch and specify your main class on the command line.

Have you tried removing the signature files? I have seen this error pop up sometimes when due to signature files as documented in "Invalid signature file" when attempting to run a.jar and Generated JAR throws ClassNotFoundException for main class is also in the similar vein.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM