简体   繁体   中英

NoClassDefFoundError on simple jar file

public class RunScript {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

I created a Java project and a package called com.klong

Inside of the package I have one .java file with the above code in it. I export it into a runnable jar file. Then I try to run the jar in a command line using this: java test.jar

When I try that, I get the following error

C:\Users\IBM_ADMIN\Tracing stuff>java test.jar
Exception in thread "main" java.lang.NoClassDefFoundError: test.jar
Caused by: java.lang.ClassNotFoundException: test.jar
    at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:653)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:619)
Could not find the main class: test.jar.  Program will exit.

I've tinkered with exporting into a normal jar file and such. I've looked at other questions about this error. I've tried using commands such as set classpath=BLEH

This project is as simple as can be so hopefully you can help me figure out this pesky error!

你需要运行java -jar test.jar ,你现在正在做的是要求java查找名为test.jar的编译类。

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