How do I resolve ClassNotFoundException?

前端 未结 22 1461
后悔当初
后悔当初 2020-11-21 06:06

I am trying to run a Java application, but getting this error:

java.lang.ClassNotFoundException:

After the colon comes the location of the cla

相关标签:
22条回答
  • 2020-11-21 06:26

    If you are using maven try to maven update all projects and force for snapshots. It will clean as well and rebuilt all classpath.. It solved my problem..

    0 讨论(0)
  • 2020-11-21 06:26

    This can happen on Windows after a java update where the old version of the java SDK is missing and a new one is present. I would check if your IDE is using the installed java SDK version (IntelliJ: CTRL + SHIFT + ALT + S)

    0 讨论(0)
  • 2020-11-21 06:30

    Add the full path of jar file to the CLASSPATH. In linux use: export CLASSPATH=".:/full/path/to/file.jar:$CLASSPATH". Other way worked (without editing the CLASSPATH) was unzipping the jar in the current project folder.

    Ways didn't work for me:

    1) Using -cp option with full path of jar file.

    2) Using -cpwith only the name of jar when located in the current folder

    3) Copying the jar to the current project folder

    4) Copying the jar to standard location of java jars (/usr/share/java)

    This solution is reported for class com.mysql.jdbc.Driver in mysql-connector-java.5-*.jar, working on linux with OpenJDK version 1.7

    0 讨论(0)
  • 2020-11-21 06:31

    Use ';' as the separator. If your environment variables are set correctly, you should see your settings. If your PATH and CLASSPATH is correct, windows should recognize those commands. You do NOT need to restart your computer when installing Java.

    0 讨论(0)
  • 2020-11-21 06:35

    To add the location of a class to your classpath via command line simply add -cp or -classpath and the location of the class while running it. I.E.

    java -cp "c:/location/of/file" YourProgram
    

    Or if you're running an IDE such as eclipse you can right click on the project -> build path -> configure build path and add the external JAR containing your class to the build path then it should work fine.

    0 讨论(0)
  • 2020-11-21 06:35

    In my case the class thrown as class not found exception has properties related to ssl certificates. Close the eclipse and open with as “Run as Administrator” then issue got resolved. As eclipse have issue related permission it will throw such kind of exception.

    0 讨论(0)
提交回复
热议问题