HP OpenVMS Systems

ask the wizard
Content starts here

Calling Java from C?

» close window

The Question is:

I am trying to write a C program that will invoke a JVM and load a java class
 file.  The question I have is what shared library do I link against so that
 when the program runs it starts up the java virtual machine.

The Answer is :

  There are different variations of having C code call Java code...
    o You have an application written in C that must call Java code.
      The usual approach is via a C fork/exec or system call, invoking
      Java at the command line.
    o If the C application accesses a access a Java applet, then the
      appletviewer is invoked as an application, or you can invoke a
      web browser and control its access -- but short of duplicating
      the Java Virtual Machine (JVM) environment, you cannot directly
      access an applet.
    o A native method call needs to a call back into the Java VM to
      invoke a Java method.  You will need to know how to set up a
      constructor to create the object, via execute_java_constructor().
      (This particular call is declared in java/include/interpreter.h.)
      Other C functions are present in this include that can permit
      access to Java methods.)

answer written or last revised on ( 21-AUG-2000 )

» close window