Can't find class java.lang.NoClassDefFoundError. (Wrong class path?)

Q

qazmlp

While creating JVM, I am getting the following error:
Can't find class java.lang.NoClassDefFoundError. (Wrong class path?)

I gave all the required Jar files in the CLASSPATH. Also, I set the
LD_LIBRARY_PATH such that, it can pick up libjvm.so available at:
/usr/java1.2/jre/lib/sparc/libjava.so

All these did not solve the problem at all.

How do I proceed ? So far, I spent 15 hours without arriving at any
solution.
Could you help?

Thanks!
 
J

Joseph Millar

While creating JVM, I am getting the following error:
Can't find class java.lang.NoClassDefFoundError. (Wrong class path?)

I assume you mean you are using the Invocation API's to create
a JVM in your application? Which version for InitArgs are you
using, 1.1 or 1.2 style? If 1.1, what is the the classpath
field set to? If you are using 1.2, which property are you
using to set classpath, -Xbootclasspath? Will need to see the
args setup and CreateJavaVM() call to really help here.
I gave all the required Jar files in the CLASSPATH. Also, I set the
LD_LIBRARY_PATH such that, it can pick up libjvm.so available at:
/usr/java1.2/jre/lib/sparc/libjava.so

Based on the error, I guess the classpath is not what it should
be, inspite of what you say ;-). Let's see the code.

The LD_LIBRARY_PATH is essential, it won't work properly without
it. But that's not your problem, the JVM is trying to start so
you are past this issue (at least temporarily), but it can't find
some required classes, which means your classpath is bogus somehow.
All these did not solve the problem at all.

How do I proceed ? So far, I spent 15 hours without arriving at any
solution.

Invocation API problems can be frustrating, the options are
obscure and tend not to be well documented. Trial and error
and experience help alot here.

--Joe
 
J

Joseph Millar

You shouldn't be setting the LD_LIBRARY_PATH. The default settings for the
LD_LIBRARY_PATH should be correct. It's strange that your VM doesn't pick
up the rt.jar; on my machine the Sun VM always prepends rt.jar. Or have
you have been tweaking the boot classpath settings?

I suspect he is trying to start the JVM using the JNI Invocation
API's inside of another app/program. That means he can't rely
on the standard java launcher which handles these details for
you. Or I could be way off base.

--Joe
 
D

dhek bhun kho

I suspect he is trying to start the JVM using the JNI Invocation
API's inside of another app/program. That means he can't rely
on the standard java launcher which handles these details for
you. Or I could be way off base.

No you're right. My mistake, I misread it. I haven't had this problem, as
I haven't done extensive coding launching a JVM from C.

Somebody else?
 
D

dhek bhun kho

this is my most dreaded error. It can have a multitude of causes.
see http://mindprod.com/jgloss/errormessages.html#NOCLASSDEFFOUNDERROR

You misread the post.

he says:
The original poster is writing that he is creating the JVM through a JNI
call in C.

http://www.inonit.com/cygwin/jni/invocationApi/launch.html
http://java.sun.com/j2se/1.4.2/docs/guide/jni/spec/invocation.html#wp15956
http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html#JNI_CreateJavaVM

I would be tempted to add the rt.jar to JavaVMOption*, but that seems an
ugly hack. Maybe it isn't, it's C after all; so it could be the only way
to do it. I was perusing the documentation to find out whether there is a
boot class path hardcoded into the Invocation API. But on the other hand
that doesn't seem likely.

Greets
Bhun.
 
J

Joseph Millar

I would be tempted to add the rt.jar to JavaVMOption*, but that seems an
ugly hack. Maybe it isn't, it's C after all; so it could be the only way
to do it. I was perusing the documentation to find out whether there is a
boot class path hardcoded into the Invocation API. But on the other hand
that doesn't seem likely.

Strictly speaking, it's not really necessary to tell the JVM where
to find its own jar files, you usually do that by simply asking
the API to fill in the default startup values, which you can then
go tweak, add to, delete from, etc. Depending on your needs and
your environment, it's sometimes easier to just make the values up
yourself, as long as you know what you need.

JNI_GetDefaultJavaVMInitArgs(void *args) is the API that fills in
the required info. It's good to call when you're just learning
so you can see what it comes back with. You will find that most
of the information it finds ends up in the system properties in
one form or other.

--Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top