JNI_CreateJavaVM

A

amatijaca

Hi there,

I was wondering if somebody knows -- when JNI_CreateJavaVM
executes from a C source code program, which java class gets
actually invoked to create a new JVM? Sooner or later, the
JNI_CreateJavaVM needs to look for a real Java class. Does
anyone know, which Java class this is??

Thanks, Alex.
 
R

Roedy Green

I was wondering if somebody knows -- when JNI_CreateJavaVM
executes from a C source code program, which java class gets
actually invoked to create a new JVM? Sooner or later, the
JNI_CreateJavaVM needs to look for a real Java class. Does
anyone know, which Java class this is??

I don't think so. That would be a chicken and egg problem. A Java
class can't execute until it has a JVM environment to run in. C needs
to load the JVM into its own address space. A C-style exec would thus
not do. In Windows, a DLL style call would be required, possibly to
java.dll.
 
A

amatijaca

Hmmm you are probably right, however, there is such a thing
as a Java compiler in tools.jar -- so, for example, your currently
running Java program can compile another (this is what happens
when JSPs are compiled -- javac.exe does not get invoked).

So, if one can call a java compiler from a running java program,
how does one running JVM create another (without going through
Runtime.getRuntime -- which is just a crutch in my opinion).. I
was thinking that JNI_CreateJavaVM kind of works the same way..

Thanks, Alex.
 
G

Gordon Beaton

I was wondering if somebody knows -- when JNI_CreateJavaVM executes
from a C source code program, which java class gets actually invoked
to create a new JVM? Sooner or later, the JNI_CreateJavaVM needs to
look for a real Java class. Does anyone know, which Java class this
is??

The JVM is created "empty". You can then use it to invoke any method
in any class you want. i.e. it doesn't have to be static void main().

/gordon
 
R

Roedy Green

Hmmm you are probably right, however, there is such a thing
as a Java compiler in tools.jar -- so, for example, your currently
running Java program can compile another (this is what happens
when JSPs are compiled -- javac.exe does not get invoked).

Your original post talked about spawning a JVM inside C in JNI, i.e.
the analog of firing up java.exe not javac.exe. Once you had a JVM
you could load the java compiler as an ordinary class. See
http://mindprod.com/jgloss/javacexe.html#MAIN
for how.
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top