Getting ClassNoFoundDef [message #290772] |
Wed, 31 August 2005 19:10 |
Eclipse User |
|
|
|
Originally posted by: sunitjoshi.netzero.com
I'm trying to run a simple java project in Eclipse3.0 and it was fine till
I tried adding a src and bin folders in the Project->Properties->Source
tab. I added a folder src under my project Ch1 and it added the bin folder
too.
Now when I try to run the Ch1, it says: java.lang.NoClassDefFoundError:
org/sj/Ch1_01
I can see the .java files under ../org/sj/Ch1_01 folder though. All the
files have the statement package org.sj; at the top.
thanks
Sunit
|
|
|
Re: Getting ClassNoFoundDef [message #290773 is a reply to message #290772] |
Wed, 31 August 2005 19:28 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
The java files need to be under the src folder. Is that where they are?
Are the .class folders in the bin folder?
Sunit Joshi wrote:
> I'm trying to run a simple java project in Eclipse3.0 and it was fine
> till I tried adding a src and bin folders in the
> Project->Properties->Source tab. I added a folder src under my project
> Ch1 and it added the bin folder too.
> Now when I try to run the Ch1, it says: java.lang.NoClassDefFoundError:
> org/sj/Ch1_01
>
> I can see the .java files under ../org/sj/Ch1_01 folder though. All the
> files have the statement package org.sj; at the top.
>
> thanks
> Sunit
>
--
Thanks,
Rich Kulp
|
|
|
Re: Getting ClassNoFoundDef [message #290774 is a reply to message #290773] |
Wed, 31 August 2005 19:37 |
Eclipse User |
|
|
|
Originally posted by: sunitjoshi.netzero.com
The bin folder is empty. The src files have the .java files (I'll confirm
that later since its on my home machine)
thanks
Sunit
|
|
|
Re: Getting ClassNoFoundDef [message #290776 is a reply to message #290774] |
Wed, 31 August 2005 19:40 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Do you have auto build turned on?
Sunit Joshi wrote:
> The bin folder is empty. The src files have the .java files (I'll
> confirm that later since its on my home machine)
>
> thanks
> Sunit
>
--
Thanks,
Rich Kulp
|
|
|
Re: Getting ClassNoFoundDef [message #290782 is a reply to message #290776] |
Thu, 01 September 2005 01:12 |
Eclipse User |
|
|
|
Originally posted by: sunitjoshi.netzero.com
I removed the src folder under Source folders on build path so that list
is empty. The Default output folder in the same dialog is set to Ch1/org/sj
My directory structure where the .java and .class files are now is
E:\Sunit\JavaFiles\Scripts\Ch1\org\sj\
However when I try to run the main class (with main), I still get this
java.lang.NoClassDefFoundError: org/sj/Ch1_01
Exception in thread "main"
Any help is appreciated.
thanks
Sunit
|
|
|
Re: Getting ClassNoFoundDef [message #290798 is a reply to message #290782] |
Thu, 01 September 2005 13:21 |
Eclipse User |
|
|
|
Originally posted by: automatic.javalobby.org
You probably didn't set the 'src' to be a Source Folder in the first instance. Then, when you created the launch configuration, it may have cached that value.
I'm assuming that there is a class Ch1_01 and it has a main method? What about right-clicking on the class and selecting 'Run As... Java Application'? Does that give the same result?
If you're running from the command line, you should be in the e:\Sunit\JavaFiles\Scripts\Ch1 directory, and the current directory '.' should be in the classpath. You'd want to have something like:
e:
cd e:\Sunit\JavaFiles\Scripts\Ch1
java -classpath .;%CLASSPATH% org.sj.Ch1_01
Lastly, this error can also be seen when you have a static field that needs to be initialised from another class, so something like:
public class Test {
private static Driver driver = Class.forName("com.ibm.db2.DB2Driver");
}
can result in a ClassNotFoundException (incorrectly reported as Test). I've also come across this a lot in code like:
public class Test {
private static Log log = LogFactory.getLog(Test.class);
}
using Log4J, but I doubt that's your problem :-)
|
|
|
Re: Getting ClassNoFoundDef [message #290803 is a reply to message #290782] |
Thu, 01 September 2005 14:28 |
Eclipse User |
|
|
|
Originally posted by: eclipse3.rizzoweb.com
Sunit Joshi wrote:
> I removed the src folder under Source folders on build path so that list
> is empty. The Default output folder in the same dialog is set to Ch1/org/sj
> My directory structure where the .java and .class files are now is
> E:\Sunit\JavaFiles\Scripts\Ch1\org\sj\
> However when I try to run the main class (with main), I still get this
>
> java.lang.NoClassDefFoundError: org/sj/Ch1_01
> Exception in thread "main"
> Any help is appreciated.
The problems you're having result from a basic misunderstanding of how
Eclipse manages Java code in Projects.
You really need to go through the Help - there is lots of information in
the Getting Started chapter of the Java Development section that will
help you understand how to organize your projects in Eclipse.
HTH,
Eric
|
|
|
Powered by
FUDForum. Page generated in 0.03688 seconds