5

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!

7
  • 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?
    – devang
    Aug 24, 2012 at 23:59
  • 4
    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.
    – Stephen C
    Aug 25, 2012 at 0:14
  • 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. Aug 25, 2012 at 0:28
  • 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.
    – Tito
    Aug 26, 2012 at 6:42
  • 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 :) Aug 26, 2012 at 6:42

2 Answers 2

2

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.