简体   繁体   中英

Broken Eclipse project - classNotFoundException - could not find main class

I have a project I've been developing in Eclipse 3.7.2 on Ubuntu 12.04. Recently, I've restructured the class hierarchy which involved moving classes between packages. I did not move my main class ("ob3.converter.Converter"), which contains my public static void main(String[] args) method.

Now, when I attempt to run it, I get:

Exception in thread "main" java.lang.NoClassDefFoundError: ob3/converter/Converter
Caused by: java.lang.ClassNotFoundException: ob3.converter.Converter
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: ob3.converter.Converter. Program will exit.

I've only ever really worked (in java) with Eclipse, which handles all the overhead for me - hence I have little understanding of this error or what could cause it. I've looked through my Run Configuration/Classpath etc but without knowing what to look for, it was fruitless.

Could anybody point me in the right direction? I've googled / search SO, and most things talk about a manifest file, but I've been unable to find it anywhere. My workspace folder contains nothing more than my source files.

I can verify:

  • The class "Converter" exists within the package "ob3.converter".
  • The class "Converter" contains a public static void main(String[] args) method.
  • The "Source" tab on the Java Build Path page in Project Properties shows "converter/lib" and "converter/src" - these 2 folders contain my entire project source.
  • The JRE used in Run Configuration/JRE is "java-6-openjdk-amd64".
  • The ClassPath tab in Run Configuration looks like this:
    • Boostrap Entries:
      • JRE System Library [java-6-openjdk-amd64]
    • User Entries:
      • converter (default classpath)
        • converter
  • The path to Converter.java has not changed since I last run it successfully.

Any help is very much appreciated!

I think you should rebuild your project. You can do this by clicking on Projects > Clean...

Sometimes the automatic build of Eclipse has problems with the refactoring or moving of classes.

I ran into this same error message. For me, I was on linux and the user issuing the java command did not have sufficient permissions to the directory of the jars on the classpath.

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