Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » ClassNotFoundException running main in one class in another project
ClassNotFoundException running main in one class in another project [message #503961] Wed, 16 December 2009 15:34 Go to next message
Eclipse UserFriend
Originally posted by: adam.hardy.no.spam.cyberspaceroad.spam

I used to do this in the previous version of Eclipse before upgrading to Galileo
but now it's not working, Eclipse says it can't even find the class.

I want to run a particular program in one project, but the class with main()
that I want to run is in a second project which is a dependency of the first.
It's a utility program and I run it this way (or would) in several projects.

In the launch configuration, I choose the main class I am talking about and
change the project to the project I am working on - which has all the resources
that this program runs on.

This worked previously, but not now - whether it is because of the upgrade or
because of the new Maven Eclipse plugin that I am using, I don't know. The Maven
Eclipse plugin builds the classpath and retrieves the jar dependencies
automatically, so I will have a bit of work to do to remove it, but I shall, to
narrow down the problem.

Here's the exception:

Exception in thread "main" java.lang.NoClassDefFoundError:
org/permacode/testdatarepo/TestDataRepoCreateXml
Caused by: java.lang.ClassNotFoundException:
org.permacode.testdatarepo.TestDataRepoCreateXml
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301 )
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320 )
Could not find the main class: org.permacode.testdatarepo.TestDataRepoCreateXml.
Program will exit.
Re: ClassNotFoundException running main in one class in another project [message #504012 is a reply to message #503961] Wed, 16 December 2009 19:50 Go to previous messageGo to next message
Walter Harley is currently offline Walter HarleyFriend
Messages: 847
Registered: July 2009
Senior Member
adam hardy wrote:
> I used to do this in the previous version of Eclipse before upgrading to
> Galileo but now it's not working, Eclipse says it can't even find the
> class.
>
> I want to run a particular program in one project, but the class with
> main() that I want to run is in a second project which is a dependency
> of the first. It's a utility program and I run it this way (or would) in
> several projects.
>
> In the launch configuration, I choose the main class I am talking about
> and change the project to the project I am working on - which has all
> the resources that this program runs on.
>
> This worked previously, but not now - whether it is because of the
> upgrade or because of the new Maven Eclipse plugin that I am using, I
> don't know. The Maven Eclipse plugin builds the classpath and retrieves
> the jar dependencies automatically, so I will have a bit of work to do
> to remove it, but I shall, to narrow down the problem.
>
> Here's the exception:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/permacode/testdatarepo/TestDataRepoCreateXml
> Caused by: java.lang.ClassNotFoundException:
> org.permacode.testdatarepo.TestDataRepoCreateXml
> at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301 )
> at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320 )
> Could not find the main class:
> org.permacode.testdatarepo.TestDataRepoCreateXml. Program will exit.


NoClassDefFoundError (NCDFE) is not the same as ClassNotFoundException (CNFE),
and it is perhaps the most poorly and confusingly named exception in the entire
Java runtime.

Despite the error message, it does NOT mean the class couldn't be found.
Instead, it means that a *dependent* class couldn't be found or initialized -
that is, TestDataRepoCreateXml was found, but it refers to some other class that
couldn't be located. And there's no easy way to find out what that class is,
unfortunately.

You can read more at
http://www.jroller.com/sjivan/entry/difference_between_class notfoundexception_and_noclassdeffounderror
..

Hopefully that'll help in your debugging. Most likely there's some missing jar
on your classpath, but it's NOT the one containing your main class.
Re: ClassNotFoundException running main in one class in another project [message #504113 is a reply to message #504012] Thu, 17 December 2009 10:30 Go to previous message
Eclipse UserFriend
Originally posted by: adam.hardy.no.spam.cyberspaceroad.spam

Walter Harley on 16/12/09 19:50, wrote:
> adam hardy wrote:
>> Here's the exception:
>>
>> Exception in thread "main" java.lang.NoClassDefFoundError:
>> org/permacode/testdatarepo/TestDataRepoCreateXml
>> Caused by: java.lang.ClassNotFoundException:
>> org.permacode.testdatarepo.TestDataRepoCreateXml
>> at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
>> at java.security.AccessController.doPrivileged(Native Method)
>> at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
>> at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
>> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301 )
>> at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
>> at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320 )
>> Could not find the main class:
>> org.permacode.testdatarepo.TestDataRepoCreateXml. Program will exit.
>
> NoClassDefFoundError (NCDFE) is not the same as ClassNotFoundException
> (CNFE), and it is perhaps the most poorly and confusingly named
> exception in the entire Java runtime.
>
> Despite the error message, it does NOT mean the class couldn't be found.
> Instead, it means that a *dependent* class couldn't be found or
> initialized - that is, TestDataRepoCreateXml was found, but it refers to
> some other class that couldn't be located. And there's no easy way to
> find out what that class is, unfortunately.

That was it.

I am aware, if caffeine levels suffice, of the difference between ClassNotFound
and NoClassDefFound but the appearance of both in the log confused me.

Thanks
Adam
Previous Topic:Working Sets mixed up?
Next Topic:What means if my folders have a square (and a cross inside of it) in the explorer?
Goto Forum:
  


Current Time: Thu Apr 25 03:46:32 GMT 2024

Powered by FUDForum. Page generated in 0.08056 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top