|
Using Javareg
Javareg is a command line tool for registering Java classes as COM (Component Object Model) components in the Microsoft® Windows® registry. This enables you to write Java classes, compile them, and then call them from any programming language (including Java) by means of COM. You can also configure your classes to be executed remotely (on a different computer) using distributed COM (DCOM).
Note The original javareg (that shipped with Microsoft® Visual J++, versions 1.0 and 1.1) supported /surrogate differently than the 3.0 pre-release version.
In its original version, javareg itself implemented a surrogate process. Now that DCOM supports a surrogate as part of
the system, and because the surrogate built into javareg was prototypical, support for the surrogate process has been dropped.
The surrogate support in DCOM was made available in Microsoft® Windows NT® 4.0 Service Pack 2 (SP2) and DCOM for Microsoft® Windows® 95.
For more information on this feature of DCOM, see the documentation in the Microsoft Win32 Software Development Kit (SDK) update for Windows NT SP2.
Javareg (version 3.0 pre-release 2) supports the following command line syntax:
javareg [/?] [/register|/unregister]
[/class:<JavaClass> [/clsid:<clsid>] [/progid:<ProgID>] [options]]
/?
| Displays command-line help and usage.
| /register
| Registers the specified Java class. The /register switch can also be used with several other switches to register a JavaBeans object as a Microsoft® ActiveX® control.
/codebase:[filename|URL]
| specifies the base location, either a URL or a filename, to obtain the Java class.
| /control
| Adds the necessary registry information to enable containers to treat the Java class as an ActiveX control. You must also use the /typelib: switch if you use this switch.
| /typelib: [filename]
| Generates the type library for this Java class at the specified filename's location.
|
| /unregister
| Unregisters the specified Java class.
| /class
| Specifes the Java class to register or unregister.
| /clsid
| Specifes the CLSID to use for the Java class (optional).
| /progid
| Specifes the ProgID to use for the Java class (optional).
| /surrogate
| Registers to run in system provided surrogate process.
| /remote: <RemoteServerName>
| Server to activate the class on (using DCOM).
| /q
| Quiet mode. Suppresses all message boxes.
|
More details on these options are provided below.
/q
| Javareg suppresses any message boxes it might display indicating success or failure. Regardless of whether this switch is specified, javareg will return 0 on success or 1 on failure.
| /register
| Javareg registers the Java class specified in the registry. If /register is specified, at least /class:<JavaClass> must also be specified. Notice that javareg will also recognize /regserver for this command.
You can use a series of switches to register a JavaBean object as an ActiveX control (mentioned previously). Notice that if you use /control to register a JavaBean, you must also generate a type library using /typelib:.
javareg /register /class:[classname] /codebase:[filename|URL]
/control /typelib:[filename]
| | | /unregister
| Javareg removes the registration information for a given Java class from the registry. If /unregister is specified, /class:<JavaClass> must also be specified. Notice that javareg will also recognize /unregserver for this command.
| /class:<JavaClass>
| This argument specifies the name of the Java class to register or unregister. If this switch is specified either /register or /unregister must also be specified. For example, the following command line will cause javareg to register the Java class Pager. Because /clsid:<clsid> is not specified, javareg will automatically generate a UUID to be used as the CLSID for the class (it uses the COM API CoCreateGUID()).
javareg /register /class:Pager
If you execute javareg again with the same Java class name, javareg will reuse the CLSID already assigned to the Java class. As such, you can execute javareg with additional switches later to reconfigure your class (for example, by specifying the /surrogate switch).
| /clsid:<clsid>
| Javareg uses the specified COM class ID (CLSID) rather than automatically generating one. For example, the following command will cause javareg to register the Java class Pager using the CLSID {2488D68A-D3BF-11D0-A145-080036006703}.
javareg /register /class:Pager
/clsid:{2488D68A-D3BF-11D0-A145-080036006703}
| /progid:<progid>
| By default, javareg does not assign a COM ProgID to your class. This switch lets you designate what ProgID to use. For example, the following command will cause javareg to register the Java class Pager and assign it the ProgID of "Pager.Java.1".
javareg /register /class:Pager /progid:Pager.Java.1
| /surrogate
| Javareg writes the appropriate registry entries necessary to enable the Java class to be activated out-of-process. This is necessary if you want your Java class to be activated and called from a different computer. In other words, you use the /surrogate switch when registering your Java class to run as a DCOM server.
For example, the following command will cause javareg to register the Java class Pager so that it can be run from a different computer and accessed through DCOM.
javareg /register /class:Pager
/clsid:{2488D68A-D3BF-11D0-A145-080036006703}
/surrogate
Notice that it is not strictly necessary to specify the CLSID when using /surrogate. If you do not, javareg will generate one.
| /remote:<RemSerNm>
| If you want to activate and call a Java class on a different computer using distributed COM, use this switch on the client computer. When using this switch, the Java class cannot be activated on the client computer, only on the server. The <RemoteServerName> can be any computer identifier supported by distributed COM. Typically, it can be a NetBIOS name, a DNS name, or a
decimal-dotted IP address.
|
The following example explains the necessary steps for using this functionality.
- Write a Java class with some public members (for example, Pager.java).
class Pager
{
public boolean Page(String PhoneNumber, String PIN, String Msg)
{
System.out.println("Page request received. Sending.");
System.out.println(" Phone: " + PhoneNumber);
System.out.println(" PIN: " + PIN);
System.out.println(" Message: " + Msg);
return true;
}
}
- Compile the Java source (into Pager.class, for example), and move the .class file to your trusted class lib directory on the server (for example, C:\WINNT\Java\TrustLib\).
- On the server, run javareg. The following shows the Pager example:
javareg /register /class:Pager /progid:Pager.Java.1
/clsid:{2488D68A-D3BF-11D0-A145-080036006703}
/surrogate
- On the client, run javareg. The following shows the Pager example (replace "yourservername" with the name of the server in the previous step):
javareg /register /class:Pager /progid:Pager.Java.1
/clsid: :{2488D68A-D3BF-11D0-A145-080036006703}
/remote:yourservername
Now you can use Microsoft® Visual Basic® to create an instance of "Pager.Java.1". For example:
Dim x As Object
Set x = CreateObject("Pager.Java.1")
fSuccess = x.Page ("555-1212", "1234", "Call Home!")
The Pager class will be activated and will run remotely on <RemoteServerName>.
|