As the frequency of .NET and Java applications increases, we're headed for an interoperability imperativewe have to get both sides to work together. One way to do that is by adding an interoperability layer that gives .NET direct access to Java classes.
by Wayne Citrin
Jan 21, 2004
Page 3 of 4
.NET classes communicate with Java classes through proxy classes. JNBridgePro generates a .NET proxy class for each Java class that you want to access from .NET. The .NET code then interacts with the proxy class, which manages the communication with the corresponding Java class. When you need an instance of a Java class, the .NET code automatically and transparently creates an instance of both the proxy and the corresponding Java object. To call a method on that Java object, you simply call the corresponding method on the proxy object. Similarly, to call a static method, you call the corresponding method on the proxy class, and to access a field in the Java object or class, you access the corresponding field on the proxy object or class.
The JNBProxy proxy generation tool creates these proxies and collects them in a .NET assembly, which appears as a DLL file that is linked into the .NET project.
To create the proxy assembly, launch the JNBProxy proxy generation tool (if it hasn't already been launched in the previous section). Specify the locations of the Java class and jar files containing the classes for which proxies will be generated by selecting the Project, Edit Classpath menu item, and then navigating to the Project\Javafolder, which contains the devX.logging.JavaClass class file, and the file log4j-1.2.8.jar from the unpacked log4j zip file. Click on the OK button when you're done.
Next, load the classes for which you wish to generate proxies into the proxy generation tool. First, select the Project, Add Classes from Classpath menu item, and then type in the class name "devX.logging.JavaClass." Make sure to check the "Include supporting classes" checkbox. Checking that option causes JNBProxy to generate proxies for all the classes that you might possibly need when accessing JavaClass. Click on the Add button, then on the OK button. JNBProxy will load approximately 200 classes. Repeat the process to load the logging classes in the log4j-1.2.8.jar file. JNBProxy will load a second set of classes.
You'll want to generate proxies for all the classes you've loaded, so select the Edit, Check All in Environment menu item. Finally, select the Project, Build menu item, navigate to the Project\DotNet folder, and enter the file name loggingProxies to generate a file named loggingProxies.dll containing the proxy classes. Figure 2 shows how the JNBProxy window looks after building the proxies. Note that you may get a warning message that some possibly required classes are missing. You can ignore this message, because these classes are necessary only if you want to log to other destinations, such as a JMS publisherand you won't be doing that in this project.