The interface for explicitly configuring or loading a JVM.
For a list of all members of this type, see IJvmLoader Members.
| Type | Description |
|---|---|
| JvmLoader | The class that acts as a factory for JVM instances. |
This interface declares the basic API for explicitly configuring the way the .NET process tries to hook up with a Java virtual machine. Remember that we don't translate Java to .NET, we bridge it. This means that at runtime your .NET types need to be able to find their corresponding Java types. Even though there are several ways you can hide the configuration details from application programmers, we recommend that you have one well defined point in your application where you attempt to connect to the Java side, detect configuration errors, and handle any problems that might have occured.
This will usually look something like this:
IJvmLoader loader = JvmLoader.GetJvmLoader();
IJvm jvm = null;
try
{
if( loader.JvmPath == null )
loader.JvmPath = @"..\jre\bin\client\jvm.dll";
loader.AppendToClassPath( @"c:\temp\myclasses.jar" );
if( loader.MaximumHeapSize < 256 )
loader.MaximumHeapSize = 256;
jvm = loader.Load();
}
catch( System.Exception se )
{
Console.WriteLine( "JVM couldn't be loaded: {0}", se.ToString() );
}
try
{
if( jvm != null )
Class.ForName( "com.myfirm.util.MyType" );
}
catch( System.Exception se )
{
Console.WriteLine( "Missing jarfile: {0}", se.Message );
}
In this example, we acquire a loader instance and configure some Java options. Notice how we use a pattern which allows the setting of default values via different configuration mechanisms. If a JvmPath is already configured, we don't reconfigure it; if a maximum Java heapsize of more than 256MB is already configured, we don't override it. Once everything is configured, we attempt to load the JVM and handle any errors that might occur at that point. If we succeeded, we attempt to load a class that we know to be required. This is a great sanity check to perform at runtime because hard-to-diagnose classpath misconfigurations (or missing jarfiles) get caught early on and don't turn into bigger problems later on.
Namespace: Codemesh.JuggerNET
Assembly: netrt (in netrt.dll)
IJvmLoader Members | Codemesh.JuggerNET Namespace