DotNetJ offers two ways of connecting to remote Java objects and use them in .NET. This can be achieved by using generated proxy classes, or with the dynamic invocation interface (DII).
 
 
 
The proxy method
This method is the standard one, it fully integrates in the .NET Remoting model. The generated proxy classes do not actually handle method calls, their only purpose is to provide the Remoting framework with the Java classes metadata (the "real" proxy classes are generated at runtime by the Remoting framework).
 
 
1- Start the server
 
DotNetJ can be used as a standalone J2SE server, or embedded in a Java application server.
To start the standalone J2SE server, use java com.overone.dotnetj.server.Server with dotnetj.jar in the classpath.
The following optional arguments can be passed to the server :
Embedding DotNetJ in a Java application server is specific to each server. See the CAROL setup guide for using DotNetJ as a protocol provider for CAROL.
 
 
2- Generate proxy classes
 
Use the Stuber tool to generate .NET proxy classes. Usage is :
Stuber [Options] ChannelUrl JavaClassNames
  Options :
  /out:OutputFile (If not specified, the assembly is given an arbitrary name and is generated in the working directory)
  /ref:ReferencedAssembliesFiles (Semi-colon separated list)
For a full description of how to use the Stuber tool, read the Stuber tool reference.
 
 
3- Add a reference to DotNetJ.dll in your project environment
 
The DotNetJ client API is needed by the .NET Remoting framework to pass method calls to the Java environment.
Note that client applications should not use the DotNetJ classes, but use the .NET Remoting framework classes and the generated proxy classes.
 
 
4- Start coding
 
using OVERONE.DotNetJ;
using anyjavapackage;
[...]
 
// Register the DotNetJ Java channel (can also be done in the application configuration file)
ChannelServices.RegisterChannel(new JavaClientChannel());
 
// Instantiate remote objects...
RemotingConfiguration.RegisterActivatedClientType(typeof(anyjavapackage.AnyJavaClass), "java://localhost:1604");
AnyJavaClass o1 = new AnyJavaClass();
AnyJavaClass o2 = new AnyJavaClass(2, "abc");
 
// ... Or obtain references to server-activated objects...
AnyJavaClass o3 = (AnyJavaClass)Activator.GetObject(typeof(AnyJavaClass), "java://localhost:1604/java?anyname:anyjavapackage.AnyJavaClass");
 
// ... And call methods
string s1 = o1.toString();
AnyJavaClass o4 = o2.getAnyJavaObject("abc");
 
 
 
 
The DII method
This method allows for the access to Java objects without generating proxy classes. It instead makes use of dynamic invocation interface classes which handle the method calls. This method does not integrate in the .NET Remoting model though it is based on the same infrastructure than the proxy method.
 
 
1- Add a reference to DotNetJ.dll in your project environment
 
The DII classes that client applications should use are located in the OVERONE.DotNetJ namespace.
 
 
2- Start coding
 
using OVERONE.DotNetJ;
[...]
 
// Instantiate remote objects...
JavaObject o1 = new JavaObject("anyjavapackage.AnyJavaClass");
JavaObject o2 = new JavaObject("anyjavapackage.AnyJavaClass", new string[] {ParameterTypeNames.INT, ParameterTypeNames.STRING}, new object[] {2, "abc"});
 
// ... And call methods
string s1 = (string)o1.Invoke("toString");
JavaObject o3 = (JavaObject)o2.Invoke("getAnyJavaObject", ParameterTypeNames.STRING, "abc");
 
// You can also access fields
string s2 = (string)o2["anyString"];
 
// References to Java arrays can be obtained
JavaArray ja1 = (JavaArray)o1.Invoke("getAnyJavaArray");
JavaObject o4 = (JavaObject)ja1[0];
ja1[1] = o4;
 
 
 
3- Start the server
 
DotNetJ can be used as a standalone J2SE server, or embedded in a Java application server.
To start the standalone J2SE server, use java com.overone.dotnetj.server.Server with dotnetj.jar in the classpath.
The following optional arguments can be passed to the server :
The Jars you wish to access from .NET should be present in the classpath.
Embedding DotNetJ in a Java application server is specific to each server. See the CAROL setup guide for using DotNetJ as a protocol provider for CAROL.
 
 
 
 
© Copyright 2003 Romain Laboisse. All rights reserved.