Creating a Java VM
Before calling
an EJB component, you need to create a Java VM using the CreateJavaVM method
of the JavaVM class. The first argument is a string that specifies
a classpath to be added to the beginning of the classpath used by
the Java VM.

The classpath argument is ignored if the Java VM is already
running.
The second argument to createJavaVM is
a boolean that specifies whether debug information
is written to a text file. See “Debugging the client”.
The JavaVM class has other methods that you can use when you
create a Java VM:
-
The CreateJavaInstance method
creates an instance of the Java object from a proxy name. -
The IsJavaVMLoaded method determines
whether the Java VM is already loaded. Use this method before calling CreateJavaVM if
you want to enable or disable some features of your application
depending on whether the Java VM has already been loaded. This will
ensure that the classpath argument passed to CreateJavaVM is ignored. -
The GetJavaVMVersion method
determines which version of the Java VM is running. -
The GetJavaClasspath method
determines the runtime classpath of the Java VM.
The JavaVM that you create using CreateJavaVM should
be a global or instance variable for the client application and
should not be destroyed explicitly.
The Java VM classpath
in the development environment
When PowerBuilder starts a Java VM, the Java VM uses internal
path and classpath information to ensure that required Java classes
are always available.
In the development environment, you can check whether the
JVM is running and, if so, which classpath it is using, on the Java
page of the System Options dialog box. The classpath is constructed
by concatenating these paths:
-
A classpath added
programmatically when the Java VM is started. For example, the classpath
you pass to the CreateJavaVM method. -
The PowerBuilder runtime static registry classpath.
This path is built into the pbjvm125.dll and
contains classes required at runtime for EJB clients and other PowerBuilder
features that use a Java VM. -
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 such as JDBC connectivity. -
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 runtime Java VM classpath
At runtime, you can use the GetJavaClasspath method
to determine what classpath the Java VM is using. The Java VM uses
the following classpath at runtime:
-
A classpath
added programmatically when the Java VM is started -
The PowerBuilder runtime static registry classpath
-
The system CLASSPATH environment variable
-
The current directory
For more information about the Java classpath at runtime,
see “Java support”.
Classes required by servers
The classpath contains the classes required by EJB clients
for EAServer. If you are using
a different J2EE server, you need to add additional classes required by
the application server to the system CLASSPATH. For example:
-
For WebLogic, weblogic.jar.
This file is installed in wlserver6.1lib or weblogic700serverlib on
the server. -
For WebSphere, JAR files installed on the server
in websphereappserverlib.
For detailed information about the files required on the client
by each application server, see the documentation for the server.
Examples
This example demonstrates the creation of an instance of the
Java VM that specifies the htmlclasses folder
in an EAServer installation as
a class path:
1 |
// global variables javavm g_jvm, <br>// boolean gb_jvm_started<br>boolean isdebug<br>string classpath<br> <br>if NOT gb_jvm_started then<br>  //create JAVAVM<br>  g_jvm = create javavm<br> <br>// The Java package for the EJB is in the <br>// EAServer html/classes folder<br>  classpath = &<br>  "D:Program FilesSybaseEAServerhtmlclasses;"<br>  <br>  isdebug = true<br>  choose case g_jvm.createJavaVM(classpath, isdebug)<br>  case 0<br>    gb_jvm_started = true<br>  case -1 <br>    MessageBox("Error", "Failed to load JavaVM")<br>  case -2<br>    MessageBox("Error", "Failed to load EJBLocator")<br>  end choose<br>end if |
This additional code can be added to the previous example
to create a record of the Java VM version and classpath used:
1 |
integer li_FileNum<br>string ls_classpath, ls_version, ls_string<br> <br>li_FileNum = FileOpen("C: empPBJavaVM.log", &<br>   LineMode!, Write!, LockWrite!, Append!)<br> <br>ls_classpath = i_jvm.getjavaclasspath()<br>ls_version = i_jvm.getjavavmversion()<br>ls_string = String(Today()) + " " + String(Now())<br>ls_string += " Java VM Version: " + ls_version<br>ls_string += " ~r~n" + ls_classpath + "~r~n"<br> <br>FileWrite(li_FileNum, ls_string)<br>FileClose(li_filenum) |