BEA Home | Events | Solutions | Partners | Products | Services | Download | Developer Center | WebSUPPORT
| WebLogic Server Doc Home | WebLogic jCOM User Guide | Previous Topic | Next Topic | Contents | View as PDF

WebLogic jCOM Tools

The following sections describe the most commonly used WebLogic jCOM tools:

- The regjvm GUI Tool

- The regjvmcmd Command Line Tool

- The java2com Tool

- The regtlb Tool

The regjvm GUI Tool

WebLogic jCOM allows languages supporting COM to access Java objects as though they were COM objects.

To do this you need to register (on the COM client machine) a reference to the JVM in which the Java objects run. The regjvm tool enables you to create and manage all the JVM references on a machine.

Note: The regjvm tool does not overwrite old entries when new entries with identical names are entered. This means that if you ever need to change the hostname or port of the machine with which you wish to communicate, you have to unregister the old entry. You can do this using the command line tool regjvmcmd.exe, or by using the GUI tool regjvm.exe (both can be found in the jCOM\bin directory).

JVM modes

A JVM may be accessed from COM clients using one of three different modes:

- DCOM mode

- Native mode (out of process)

- Native mode in process

DCOM mode

DCOM mode does not require any native code on the Java server side, which means your Java code may be located on a Unix machine or any machine with a Java Virtual Machine installed. When you register the JVM on the Windows client machine you define the name of the server host machine (it may be localhost for local components) and a port number.

The Java code in the JVM must call com.bea.jcom.Jvm.register("<jvm id>"), where <jvm id> is the id of the JVM as defined in regjvm. The JVM must also be started with the JCOM_DCOM_PORT property set to the port defined in regjvm tool for the specified <jvm id>.

Native mode (out of process)

Native mode currently only works on the local machine. Other than the JVM name no additional parameters are necessary.

The JVM must call com.bea.jcom.Jvm.register("<jvm id>"), where <jvm id> is the id of the JVM as defined in regjvm. The JVM must also be started with the JCOM_NATIVE_MODE property set.

Native mode in process

Using native mode in process allows the user to actually load the Java object into the same process as the COM client. Both objects must of course be located on the same machine.

The JVM need not call com.bea.jcom.Jvm.register() or be started as an extra process to the client.

The User Interface of the regjvm GUI Tool

When you run the regjvm tool, a dialog is displayed. The dialog is split into two parts:

- The top part is for selection and management of all JVMs on the current machine. JVMs may be added, altered or deleted. Before switching to a different JVM, changes made to the currently selected JVM must be saved. It is also here that the different JVM modes can be selected which then dictates the information required in the lower half of the window.

- The lower half of the windows contains the details required for each JVM, according to the mode of the JVM. In addition to the JVM details there is an advanced checkbox which when selected displays advanced options for each JVM mode.

  The meanings of these options are discussed in the following sections.

DCOM Mode Options for the regjvm GUI Tool

Standard Options

- Hostname (required) - The IP name or IP address where the JVM is located.

- Port (required) - The port used to initiate contact with the JVM.

Advanced Options

- Launch command (optional) - The command to be used if the JVM is to be automatically launched. Typically this would be something like: c:\bea\jdk131\bin\java -classpath c:\bea\wlserver6.1\jcom\lib\jcom.jar; c:\pure MyMainClass.

- Launch options (optional) - Allows you to specify the initial window state of the server component.

- Generate Script... (optional) - Allows the user to generate a registry script selecting the settings of the JVM.

Native Mode Options for the regjvm GUI Tool

Standard Options

There are no standard options for this mode.

Advanced Options

- Launch command (optional) - see DCOM mode.

- Launch options (optional) - see DCOM mode.

- Generate Script... (optional) - see DCOM mode.

Native Mode in Process Options for the regjvm GUI Tool

Standard Options

- JVM (required) - The JVM must be specified. Clicking the browse button allows you to select your own JVM, clicking the Scan button scans your local machine for JVMs (this may take a few minutes) and inserts them in the listbox for your selection.

Advanced Options

- Classpath (optional) - The CLASSPATH for the JVM - if this is left blank the CLASSPATH environment variable at runtime is used. Otherwise the contents are added to the CLASSPATH environment variable.

- Main class (optional) - The name of the class containing a Main method which you wish to be called.

- Properties (optional) - Any properties which you require to be set. Must have the following syntax: prop1=value1 prop2=value2...

- Java 2 (optional) - When setting properties this must be set when using Java 2 (JDK 1.2.x, 1.3.x) and cleared when using 1.1.x.

- Generate Script... (optional) - see DCOM mode.

The regjvmcmd Command Line Tool

regjvmcmd is the command line version of the GUI tool, regjvm, discussed above. To get a summary of its parameters, run regjvmcmd without parameters.

In its simplest form, you specify:

- a jvm ID (corresponding to the name used in com.bea.jcom.Jvm.register("JvmId")),

- and the binding that can be used to access the JVM, in the form hostname[port], where hostname is the name of the machine running the JVM, and port is the TCP/IP port specified when starting the JVM by setting the JCOM_DCOM_PORT property (e.g. java -DJCOM_DCOM_PORT=1234 MyMainClass).

If you no longer need to have the JVM registered, or if you wish to change its registration, you must first un-register it using regjvmcmd /unregister JvmId

The java2com Tool

The java2com tool analyzes Java classes (using Java's reflection mechanism), and outputs:

- a COM Interface Definition Language (IDL) file

- pure Java DCOM marshalling code (wrappers) used by the WebLogic jCOM runtime to facilitate access to the Java objects from COM using vtable (late binding) access.

The IDL file has to be compiled using Microsoft's MIDL tool.

To generate the IDL file and the wrappers, start the java2com tool using the command:

>     java com.bea.java2com.Main

You can run this tool on any platform. Make sure that the WebLogic jCOM runtime jCOM.jar is in your CLASSPATH environment variable.

The java2com tool displays the following dialog box:

The dialog box has the following fields (any changes to the configuration are automatically saved when you exit the dialog box):

1. Java Classes & Interfaces

   These are the 'root' Java classes and interfaces that you want java2com to analyze. They must be accessible in your CLASSPATH. WebLogic jCOM analyzes these classes, and generates COM IDL definitions and Java DCOM marshalling code which can be used to access the Java class from COM. It then performs the same analysis on any classes or interfaces used in parameters or fields in that class, recursively, until all Java classes and interfaces accessible in this manner have been analyzed.

   Separate the names with spaces. Click on the ... button to display a dialog that lists the classes and lets you add/remove from the list.

2. Name of Generated IDL File

   This is the name of the COM Interface Definition Language (IDL) file which will be generated. If you specify myjvm, then myjvm.idl will be generated. This name is also used for the name of the type library generated when you compile myjvm.idl using Microsoft's MIDL compiler.

3. Output Directory

   The directory to which java2com should output the files it generates. The default is the current directory (".").

4. Dump Analysis

   Displays the classes that the java2com discovers, as it discovers them.

5. Save Settings/Load Settings

   Click on the Save Settings button to save the current java2com settings.

   When java2com starts, it checks to see if there is a java2com.ser setting file in the current directory. If present, it loads the settings from that file automatically.

6. Names...

   Clicking the Names button displays the following dialog box:
   When '*' is selected from the class/interfaces names drop-down list, a text box is displayed into which you can type the name of a member (field or class) name. You may specify a corresponding COM name to be used whenever that member name is encountered in any class or interface being generated. If you leave the name blank then that Java member will not have a corresponding member generated in any COM interface.

   When a specific COM class name or interface is selected from the class/interfaces names drop-down list, the set of members in that class or interface is listed below it. You may specify a COM name to be used, and by clicking on Add this Class Name map you map the selected class/interface to the specified COM name. By clicking on Add this Member Name map you may map the selected member to the specified COM name.

7. Generate button

   Generates the wrappers and IDL file.

For each public Java interface that java2com discovers, it creates a corresponding COM interface definition. If the Java interface name were: com.bea.finance.Bankable, then the generated COM interface would be named ComBeaFinanceBankable, unless you specify a different name using the 'Names ...' dialog.

For each public Java class that java2com discovers, it creates a corresponding COM interface definition. If the Java class name were: com.bea.finance.Account, then the generated COM interface would be named IComBeaFinanceAccount, unless you specify a different name using the 'Names ...' dialog. In addition if the Java class has a public default constructor, then 'java2com' generates a COM class ComBeaFinanceAccount, unless you specify a different name using the 'Names ...' dialog.

If a Java class can generate Java events, then the generated COM class will have source interfaces (COM events) corresponding to the events supported by the Java class.

Compile the generated IDL file using Microsoft's MIDL tool. This ships with Visual C++, and can be downloaded from the MS web site. The command

>     midl prodServ.idl

will produce a type library called prodServ.tlb, which can be registered as described in the following section.

The regtlb Tool

WebLogic jCOM's regtlb tool registers a type library on a COM Windows client that wishes to access Java objects using COM's early binding mechanism. regtlb takes two parameters. The first is the name of the type library file to be registered. The second is the ID of the JVM in which the COM classes described in the type library are to be found:

If the type library was generated from an IDL file that was in turn generated by the WebLogic jCOM java2com tool, then the regtlb command can automatically determine the Java class name corresponding to each COM class in the type library (the COM class descriptions in the type library are of the form:

>     Java class java.util.Observable (via jCOM))

If the type library was not generated from a java2com generated IDL file, you will be prompted to give the name of the Java class which is to be instantiated for each COM class:

This means that when someone attempts to create an instance of Atldll.Apple, WebLogic jCOM will instantiate com.bea.MyAppleClass in the JVM MyJvm. The MyAppleClass class should implement the Java interfaces generated by WebLogic jCOM's java2com tool from atldll.tlb that are implemented by the COM class Atldll.Apple.

Copyright © 2001 BEA Systems, Inc. All rights reserved. Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.