JNI_CreateJavaVM, class loading and jre/lib/ext directory

N

Naresh Agarwal

Hi

I've a C++ application, which creates a VM and use some Java classes. I
create the VM using "JNI_CreateJavaVM" API. When I try to create a Java
class object using JNI call, where all, the .class file will be
searched by JVM?

If I create a jar file out of my classes and put that in jre\lib\ext,
will VM be able to locate and load it?

In other words, when a VM created from a C++ code, and a Java class is
instantiated using JNI calls, does VM searches the .class definition in
jre\lib\ext directory or it searches only in system classpath?

thanks & regards,
Naresh Agarwal
 
J

jan V

In other words, when a VM created from a C++ code, and a Java class is
instantiated using JNI calls, does VM searches the .class definition in
jre\lib\ext directory or it searches only in system classpath?

That really sounds like a question which ought to be explained in the JNI
Spec/docs. RTM?
 
N

Naresh Agarwal

I went through Sun documentation but could not find a clear answer.

thanks & regards,
Naresh Agarwal
 
J

jan V

I went through Sun documentation but could not find a clear answer.

I'm a big believer in negative feedback. I would find the author(s) of the
JNI API and its documentation, and email them directly with your concerns.
If the docs really don't mention how the classes are found when
instantiating a JVM.. then that's definitely not good enough. The authors
need to know this, and they will probably thank you for pointing out this
hole in their documentation. They're only human too...
 
G

Gitta Zahn

Naresh said:
I've a C++ application, which creates a VM and use some Java classes. I
create the VM using "JNI_CreateJavaVM" API. When I try to create a Java
class object using JNI call, where all, the .class file will be
searched by JVM?

You need to specify the class path the JVM shall use within
the parameters of JNI_CreateJavaVM().

Read the documentation of JNI_CreateJavaVM - it contains an example:
http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-12.html#JNI_CreateJavaVM

Gitta
 
N

Naresh Agarwal

Thanks Gitta.

My question is slightly different. In a normal Java program, JVM is
able to load the user defined Java classes from following places -

1. system classpath.
2. "jre\lib\ext" directory

Is this also true while instantiating a Java class from C++ code using
JNI calls (after creating VM)? We need to provide the system classpath
while creating the VM, but is #2 taken care of automatically by VM?

thanks
Naresh Agarwal
 
R

Roedy Green

I'm a big believer in negative feedback. I would find the author(s) of the
JNI API and its documentation, and email them directly with your concerns.
If the docs really don't mention how the classes are found when
instantiating a JVM

To solve the question yourself, the instant you have a JVM
instantiated, query the system properties.

See http://mindprod.com/applets/wassup.html


--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
N

Naresh Agarwal

Have another question on similar lines.

If I put a jar file ABC.jar in jre/lib/ext, Do I need to put the
dependencies of this jar file (i.e., jar files which are required by
ABC.jar) in jre/lib/ext?

Can I put ABC.jar in jre/lib/ext and its dependencies in system
classpath?

thanks & regards,
Naresh Agarwal
 
R

Roedy Green

If I put a jar file ABC.jar in jre/lib/ext, Do I need to put the
dependencies of this jar file (i.e., jar files which are required by
ABC.jar) in jre/lib/ext?

Can I put ABC.jar in jre/lib/ext and its dependencies in system
classpath?

Think of the ext directory as just shorthand for putting all the jars
in the ext directory on the classpath.

All that can happen from your tweaking putting jars on the classpath
or ext is it will run faster or slower. You want the most frequently
used stuff near the head of the classpath.

If there are duplicate classes, it will find the first one, but there
should not be any.

If you are concerned about speed finding classes, you might look into
the manifest Class-Path and the JarIndex.

Have a look at how a Classloader works. It is much simpler than you
might imagine.

see http://mindprod.com/jgloss/classloader.html
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top