You can develop Java MTS components using tools provided by MTS and Visual J++. It is also recommended that you install the latest version of the Microsoft SDK for Java, available at http://www.microsoft.com/java.
This section contains the following topics:
Implementing a Component in Java
To implement a component in Java, follow these steps
This will create a set of Java class files, typically under \%systemroot%\Java\Trustlib. It will create one class file for each custom interface, and one class file for each coclass in the library.
To specify the custom attributes in a type library, add the following in your IDL or ODL file:
#include <JavaAttr.h>
Within the attributes section of a coclass, specify the JAVACLASS:
JAVACLASS("package.class")
You may optionally specify a PROGID:
PROGID("Progid")
For example:
[
uuid(a2cda060-2d38-11d0-b94b-0080c7394688),
helpstring("Account Class"),
JAVACLASS("Account.AccountObj"),
PROGID("Bank.Account.VJ"),
TRANSACTION_REQUIRED
]
coclass CAccount
{
[default] interface IAccount;
};
EXEGEN is the Java executable file generator. To use this file, copy it to the appropriate destination folders (usually \JavaSDK\bin). This version of EXEGEN.EXE is capable of creating DLL files from Java classes, and can also include user-specified resources in its output files. This version of EXEGEN no longer supports the /base: directive. Class files are always included with the proper name. It supports a new /D directive that causes it to generate a DLL file instead of an EXE.
EXEGEN is now capable of reading five types of input files:
If you use EXEGEN to create a DLL, the DLL can self-register any included Java classes that implement COM objects. There are two ways to tell EXEGEN which classes should be registered:
– or –
Required keyword.
Optional keyword that specifies the clsid GUID. If omitted, EXEGEN chooses a unique GUID.
Optional keyword. If omitted, the class will be registered without a progid.
When an MTS method uses a GUID parameter, you must pass an instance of class com.ms.com._Guid. Do not use class Guid, CLSID or IID from package com.ms.com; they will not work and they are deprecated. The definition of class _Guid is:
package com.ms.com;
public final class _Guid {
// Constructors
public _Guid (String s);
public _Guid (byte[] b);
public _Guid (int a, short b, short c,
byte b0, byte b1, byte b2, byte b3,
byte b4, byte b5, byte b6, byte b7);
public _Guid ();
// methods
public void set(byte[] b);
public void set(String s);
public void set(int a, short b, short c,
byte b0, byte b1, byte b2, byte b3,
byte b4, byte b5, byte b6, byte b7);
public byte[] toByteArray();
public String toString();
}
Instances of this class can be constructed from a String (in the form “{00000000-0000-0000-0000-000000000000}”), from an array of 16 bytes, or from the usual parts of a Guid. Once constructed, the value can also be changed. Method toByteArray will return an array of 16 bytes as stored in the Guid, and method toString will return a string in the same form used by the constructor.
JAVAGUID.EXE
Microsoft Transaction Server supplies a tool, JAVAGUID.EXE, that will post-process the output of JAVATLB. The following occurs for each class file:
The clsid and iid members that JAVAGUID adds are useful as parameters to IObjectContext.CreateInstance and ITransactionContextEx.CreateInstance.
JAVAGUID can only be executed from the command line. It takes one or more parameters which are names of class files to update.
JAVATLB will eventually be updated to make JAVAGUID unnecessary.
Using an MTS Component from Java
To use an MTS component from Java, run the Java Type Library Wizard against the type library for the component. This will create several Java class files, typically under \%systemroot%\Java\TrustLib. It will create one class file for each custom interface, and one class file for each coclass in the library.
Assume, for example, that the type library contained one interface named IMyInterface, and one coclass, named CMyClass.
From Java, you can create a new instance of the component by executing
new CMyClass()
If you want to control transaction boundaries in the class, you can execute
ITransactionContextEx.CreateInstance ( CMyClass.clsid, IMyInterface.iid )
You should never call Java’s new operator on the class that you implemented. Instead, use one of the following techniques:
All of these techinques will result in the creation of a new instance of the class that you implemented.
Using the Java Sample Bank Components
The Java Sample Bank components are automatically configured by MTS Setup and require no additional steps in order to run them.
If you want to recompile the Java Sample Bank components, follow these steps: