Proyecto Eclipse roto - classNotFoundException - no se pudo encontrar la clase principal

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) método.

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) método.
  • 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)
        • convertidor
  • The path to Converter.java has not changed since I last run it successfully.

¡Cualquier ayuda es muy apreciada!

preguntado el 25 de agosto de 12 a las 00:08

If you could post a screenshot of your eclipse with the package structure expanded, and Converter class opened in the editor. Does your project show any error in the package explorer? Any errors in the Problems view? -

Have you tried the standard tricks for dealing with a "confused" Eclipse workspace? Refresh (F5) the workspace. Restart Eclipse. Close / open the project. Delete the project (DO NOT check delete from disk!!!) and reimport it. -

When you say run, I assume you are clicking the run icon at the top. Try right clicking the Converter class in the package view and select run as -> java application. -

tried checking the run configuration of the project ? If a project contains many classes with the main method,you have to select which class' main method should be executed from the run configurations. -

Hey guys thank you for your advice. Closing/reopening the project removed the red exclamation mark from the Project Icon. Refreshing the project, restarting Eclipse and rebooting machine appeared to change nothing. Deleting the project and reimporting it solved the problem!!! Thank you Stephen C - post that as an answer and I'll accept it :) -

2 Respuestas

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.

Respondido el 14 de Septiembre de 12 a las 20:09

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.

Respondido el 16 de Septiembre de 13 a las 19:09

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.