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 :
-
debug
Starts the server in debug mode.
-
port:[a TCP port]
Sets the TCP port for the server. If not specified, a default port (1604) is used.
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)
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;
[...]
ChannelServices.RegisterChannel(new JavaClientChannel());
RemotingConfiguration.RegisterActivatedClientType(typeof(anyjavapackage.AnyJavaClass), "java://localhost:1604");
AnyJavaClass o1 = new AnyJavaClass();
AnyJavaClass o2 = new AnyJavaClass(2, "abc");
AnyJavaClass o3 = (AnyJavaClass)Activator.GetObject(typeof(AnyJavaClass), "java://localhost:1604/java?anyname:anyjavapackage.AnyJavaClass");
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;
[...]
JavaObject o1 = new JavaObject("anyjavapackage.AnyJavaClass");
JavaObject o2 = new JavaObject("anyjavapackage.AnyJavaClass", new string[] {ParameterTypeNames.INT, ParameterTypeNames.STRING}, new object[] {2, "abc"});
string s1 = (string)o1.Invoke("toString");
JavaObject o3 = (JavaObject)o2.Invoke("getAnyJavaObject", ParameterTypeNames.STRING, "abc");
string s2 = (string)o2["anyString"];
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 :
-
debug
Starts the server in debug mode.
-
port:[a TCP port]
Sets the TCP port for the server. If not specified, a default port (1604) is used.
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.