Exception in thread “main” java.lang.NoClassDefFoundError: HelloWorld

前端 未结 4 1400
长情又很酷
长情又很酷 2020-12-13 11:46

I\'ve been working on this for about an hour and thumbing through Q&As on stackoverflow but I haven\'t found a proposed solution to my problem. I\'m sorry if this is a d

4条回答
  •  半阙折子戏
    2020-12-13 12:18

    Problem: Basically, the Exception in thread "main" java.lang.NoClassDefFoundError:

    means, that the class which you are trying to run was not found in the classpath.

    Solution: you need to add the class or .jar file which contains this class into the java classpath. When you are running a java class from the command line, you need to add the dot (.)

    java YourSingleClass -cp .
    

    into the classpath which tells the JVM to search for classes in actual directory.

    If you are running a class from a .jar file, you need to add this jar file into the classpath:

    java org.somepackage.SomeClass -cp myJarWithSomeClass.jar
    

提交回复
热议问题