Microsoft SDK for Java

Using Jactivex with COM

The jactivex utility is mainly used for hosting Automation-enabled Microsoft® ActiveX® Controls in Java. However, you can also use jactivex to generate .java files for the classes and interfaces described in a type library. These .java files, once compiled into .class files, allow Java programs to use Component Object Model (COM) services.

Note   Jactivex replaces javatlb and jcom.

To use a COM class from Java, you must first import it; this means creating a Java class that represents the COM class in the context of Java. The jactivex tool uses the COM type library information to create Java classes that represent COM interfaces.

A type library is a mechanism defined by COM to define type information. Each type library contains complete type information about one or more COM entities, including classes, interfaces, and dispinterfaces. For more information about type libraries, see the MSDN™ Library. To find out how to use the interfaces available from a particular programmable control or Automation server, see the documentation provided by that vendor.

Note   The jactivex tool is virtually identical to the jcom tool and similar to the javatlb tool. Jactivex generates Java source code (.java) rather than the .class files that javatlb generates. The generated Java source requires new functionality not present in older versions of the compiler in Microsoft® Visual J++®. For more information, see Configuring Jactivex.

To use the jactivex tool for low-level Java/COM integration (that is, enabling the javatlb behavior), use the /javatlb switch and provide the name of a type library as follows:

jactivex /javatlb <file name>

Where <file name> is the file name of the type library (*.tlb, *.olb, *.ocx, *.dll or *.exe) to import.

Note   If you specify an .ocx file without the /javatlb switch, the jactivex tool will generate a JavaBean wrapper for the ActiveX control (its default operation).

This command generates .java files for the classes and interfaces described by a type library. These .java files, once compiled into .class files, allow Java programs to use COM services.

For example, the following command line creates a \Widgets subdirectory underneath the trusted library directory (specified by the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\Java VM\TrustedLibsDirectory):

jactivex /javatlb widgets.tlb

If the trusted library directory is \%Windir%\Java\Trustlib, the preceding command creates the directory \%Windir%\Java\Trustlib\Widgets, and fills it with .java files. A separate .java file is created for each class, structure, enumeration, and interface described by the widgets.tlb type library. The names of packages and directories created by jactivex contain only lowercase letters.

If the type library contains an importlib statement, jactivex creates a separate Java package in a separate directory for the imported type library.

Configuring Jactivex addresses backward-compatibility issues with javatlb.

Generating COM Interfaces from Type Libraries discusses the use of Jactivex with the /javatlb /c2j command-line option.

Example of Using COM objects in Java Code shows how to use COM objects in Java code.

© 1999 Microsoft Corporation. All rights reserved. Terms of use.