JavaVM:
CreateJavaVM method
Description
Loads and initializes a Java VM or attaches an existing Java
VM to the current process.
Syntax
1 |
<span>javavm</span>.createJavaVM(string <span>classpath</span>, boolean <span>isdebug</span>) |
Argument |
Description |
---|---|
javavm |
An instance of the JavaVM class |
classpath |
A string specifying the classpath that |
isdebug |
A boolean that determines whether debug |
Return Values
Integer. Returns one of the following
integer values:
-
1
Success. The Java VM had already been loaded and was attached
to the current process. -
0
Success. The Java VM was loaded and initialized and attached
to the current process. -
-1
Failure. The Java VM was not loaded, possibly because jvm.dll was
not found in the classpath. -
-2
Failure. The pbejbclient126.jar file
was not found.
Examples
This example shows how createJavaVM might
be used with a connection to EAServer:
1 |
JavaVM l_jvm<br>EJBConnection l_ejbconn<br>java_integer val<br>long rc<br>l_jvm = CREATE JavaVM<br>l_EJBConn = CREATE EJBConnection<br> <br>TRY<br>  IF l_jvm.<span>createJavaVM</span>("", false) >= 0 THEN<br>    string ls_props[]<br>    ls_props[1] = "javax.naming.Context.INITIAL_CONTEXT_FACTORY=<br>      com.sybase.ejb.InitialContextFactory"<br>    ls_props[2] ="javax.naming.Context.PROVIDER_URL=iiop://localhost:9000"<br>    ls_props[3] = "javax.naming.Context.SECURITY_PRINCIPAL=jagadmin"<br>    ls_props[4] = "javax.naming.Context.SECURITY_CREDENTIALS=jagadmin"<br>    l_EJBConn.connectToServer(ls_props)<br>    l_EJBConn.createJavaInstance(val, "java_integer")<br>    val.java_integer(17)<br>    MessageBox("The value is", val.IntValue())<br>  ELSE<br>    MessageBox("createJavaVM", "Failed", StopSign!)<br>  END IF<br>CATCH (Throwable g)<br>  MessageBox("Exception in createJavaInstance", g.getMessage())<br>END TRY |
Usage
The isdebug argument is used to record
information about the Java VM, including class loads, in the file VM.out in
the directory where the current application is located.
The classpath argument must include the
classes and JAR files required by the server, if they are not already
listed in the classpath used by the Java VM.
running
Files and directories passed only in the classpath argument
are not available to the Java VM if it has already been started
by another process. In the development environment, you can check
whether the Java VM is running and, if so, which classpath it is
using, on the Java page of the System Options dialog box. At runtime,
you can use the IsJavaVMLoaded method to determine whether
the Java VM is already running, and the GetJavaClasspath method to find the classpath.
In the development environment, the classpath used by the
Java VM is constructed by concatenating these paths:
-
A classpath added programmatically when the JVM is started.
For example, the classpath you pass to this method. -
The PowerBuilder runtime static registry classpath.
This path is built into the pbjvm126.dll and
contains classes required at runtime for features such as PDF generation
and EJB clients. -
The PowerBuilder system classpath. This path resides
in a Windows registry key installed when you install PowerBuilder.
It contains classes required at design time for Java-related PowerBuilder
features. -
The PowerBuilder user classpath. This is the path
that you specify on the Java page of the System Options dialog box. -
The system CLASSPATH environment variable.
-
The current directory.
The JVM uses the following classpath at runtime:
-
A classpath added programmatically when the JVM is started
-
The PowerBuilder runtime static registry classpath
-
The system CLASSPATH environment variable
-
The current directory