JNI and

Y

yshamama

Hi all

I am using java from C++ using JNI calls
the JVM created when the C++ application is started
and destroyed just before it stop running

While my C++ app is running I am creating new class in java
and I want to use them using JNI calls
but the I can't found the class because its not in the classpath

what should I do ???

thanks
 
G

Gordon Beaton

While my C++ app is running I am creating new class in java and I
want to use them using JNI calls but the I can't found the class
because its not in the classpath

Specify a classpath argument when you create the JVM.

/gordon
 
Y

yshamama

Hi

Thanks for your quick reply but my problem is that my classes is in a
jar file
and I don't have the location of the jar when I'm creating the JVM.
I get is location only after I alreay create the JVM.
I need a way to load the classes in that jar after I create the JVM
even if the jar file is not the classpath.

Thanks
 
C

Chris Uppal

[..] but my problem is that my classes is in a jar file
and I don't have the location of the jar when I'm creating the JVM.

Then your problem is /exactly/ the same as it would be if you were working in
Java directly, nothing whatever to do with JNI. The solution is also exactly
the same: create your own classloader (probably a java.net.URLClassLoader) and
use that to load code from the jar file.

(Actually you do have another option using JNI -- you could extract the
classfiles from the JAR file and then inject the bytecode into the JVM directly
using the DefineClass() function in JNI. Offhand, I can't think of any good
reason for wanting to do it that way, though.)

-- chris
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top