NoClassDefFoundError [message #169278] |
Mon, 04 September 2006 16:05 |
Eclipse User |
|
|
|
Originally posted by: public.room32.net
I am working with Bruce Eckel's Thinking In Java 4
I have created a project and added his net.mindview.util library (a class
folder) containing a print method to the Build Path ( Java Build Path >
Libraries > Add Class Folder > Create New Folder... > Advanced)
I assumed it worked since eclipse will compile the following program with
no errors:
package myPackage;
import static net.mindview.util.Print.*;
public class Test{
public static void main(String[] args) {
print("abcdefg");
}
}
but there is a runtime error:
Exception in thread "main" java.lang.NoClassDefFoundError:
myExtLIb/net/mindview/util/Print
at myPackage.Test.main(Test.java:14).
so now JDT cannot find the byte code for print() ? I thought eclipse
already checked for these dependencies.
The Eclipse help describes the process of linking class files:
"In order to still benefit from external .class files, a class folder
must be mounted as a linked folder in Eclipse workspace (in project
properties, select Java Build Path > Libraries > Add Class Folder > Create
New Folder... > Advanced. Then a folder name can be associated with an
arbitrary file system location by checking "Link to folder on the file
system). "
I thought that was it, but then it goes on:
"Once mounted, the linked class folder can normally be referenced on a
build path, and from there on programs can be compiled against it."
do I further have to reference my linked classes? and if so; where/how?
thanks,
john
|
|
|
Re: NoClassDefFoundError [message #169382 is a reply to message #169278] |
Tue, 05 September 2006 04:05 |
Eclipse User |
|
|
|
Originally posted by: eclipse4.rizzoweb.com
john doe wrote:
> I am working with Bruce Eckel's Thinking In Java 4
>
> I have created a project and added his net.mindview.util library (a
> class folder) containing a print method to the Build Path ( Java Build
> Path > Libraries > Add Class Folder > Create New Folder... > Advanced)
[snip]
>
> but there is a runtime error:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> myExtLIb/net/mindview/util/Print
> at myPackage.Test.main(Test.java:14).
>
> so now JDT cannot find the byte code for print() ? I thought eclipse
> already checked for these dependencies.
Remember that the build path is separate from any runtime classpath. You
included the .class files on your project build path, but when you
launch the application the runtime classpath does not include that same
location for some reason.
You need to edit the Launch Configuration to include the .class folder.
The Eclipse Help contains all the details you need about Launch
Configurations.
Hope this helps,
Eric
|
|
|
|
Re: NoClassDefFoundError [message #169468 is a reply to message #169382] |
Tue, 05 September 2006 10:18 |
Eclipse User |
|
|
|
Originally posted by: public.room32.net
hm ... although I wasn't aware of the launch configuration before you
mentioned it, it does seem that this automatically have copied the
settings from the projects properties. Certainly the same entries are
present in the classpath tab of the 'Modify Atributes and Launch'-window
for the current class.
do you always set these Launch settings by hand yourself?
|
|
|
Re: NoClassDefFoundError [message #169568 is a reply to message #169468] |
Tue, 05 September 2006 14:42 |
Eclipse User |
|
|
|
Originally posted by: eclipse4.rizzoweb.com
John Doe wrote:
> hm ... although I wasn't aware of the launch configuration before you
> mentioned it, it does seem that this automatically have copied the
> settings from the projects properties. Certainly the same entries are
> present in the classpath tab of the 'Modify Atributes and Launch'-window
> for the current class.
>
> do you always set these Launch settings by hand yourself?
>
Not always, but sometimes. It is not always the case that the runtime
classpath should be the same as the build path; in those cases, or when
there is extra configuration needed for running an app, I do edit the
Launch Configs by hand.
So are you saying that the .class files appear to be on the launch
classpath but your app is still failing to find them?
Eric
|
|
|
Re: NoClassDefFoundError [message #169878 is a reply to message #169278] |
Thu, 07 September 2006 03:26 |
Eclipse User |
|
|
|
Originally posted by: wegener.cboenospam.com
john doe wrote:
> I am working with Bruce Eckel's Thinking In Java 4
>
> I have created a project and added his net.mindview.util library (a
> class folder) containing a print method to the Build Path ( Java Build
> Path > Libraries > Add Class Folder > Create New Folder... > Advanced)
>
> I assumed it worked since eclipse will compile the following program
> with no errors:
>
> package myPackage;
> import static net.mindview.util.Print.*;
>
> public class Test{
>
> public static void main(String[] args) {
> print("abcdefg");
> }
> }
>
> but there is a runtime error:
>
> Exception in thread "main" java.lang.NoClassDefFoundError:
> myExtLIb/net/mindview/util/Print
> at myPackage.Test.main(Test.java:14).
>
> so now JDT cannot find the byte code for print() ? I thought eclipse
> already checked for these dependencies.
> The Eclipse help describes the process of linking class files:
>
....snip
Are you sure that you have compiled the class. The error message that
you posted doesn't match up with the source that you posted. The stack
trace indicates that the error occurs at line 14. However, your source
code looks like it only has 9 lines. The package name for the
exceptions also indicates that the missing package is
myExtLib.net.minview.util. Is it possible that you have an old version
of the class somewhere in your project?
|
|
|
Powered by
FUDForum. Page generated in 0.08418 seconds