Class SetupJVMWrapper
Main entry point for JVM languages setup and execution.
public class SetupJVMWrapper : IJVMWrapperManagement
- Inheritance
-
SetupJVMWrapper
- Implements
- Derived
- Inherited Members
- Extension Methods
Examples
This is a basic example showing SetupJVMWrapper class usage
class JVMWrapperApp : SetupJVMWrapper
{
public void Execute()
{
ImportPackage("java.lang");
ImportPackage("java.util");
var str = DynJVM.String.@new();
str = str.concat("HELLO WORLD FROM JVM!!!"); // this command is executed within the JVM context
Console.WriteLine("Output from JVM: {0}", str);
}
}
To run use:
applicationName --JVMPath:[ABSOLUTE PATH TO JRE LIBRARY (jvm.dll/libjvm.so)]
Other command line switch are available on https://www.jcobridge.com/command-line-options/
Constructors
SetupJVMWrapper()
Initialize a new instance of SetupJVMWrapper
public SetupJVMWrapper()
SetupJVMWrapper(string)
Initialize a new instance of SetupJVMWrapper
public SetupJVMWrapper(string destinationPath)
Parameters
destinationPath
stringThe path where runtime info will be sent
Remarks
Not available using Nuget packages
Properties
ClassPath
The starting JVM class path. Further path can be added later.
public virtual string ClassPath { get; }
Property Value
Remarks
It is not the same classpath switch available in CLI. No wildcards expansion is made at this level. Use ClassPathBuilder in this case.
ContainerId
Return a string identifier of the container instance
public static string ContainerId { get; }
Property Value
DebugSuspendFlag
Enables Debug
public virtual string DebugSuspendFlag { get; }
Property Value
DisableOpenOnJavaNio
true to close access to java.nio module i.e. removes --add-opens=java.base/java.nio=ALL-UNNAMED on JVM parameters, default value is false
public virtual bool DisableOpenOnJavaNio { get; }
Property Value
DynJVM
The dynamic entry point for JVM operations. It permits to write code in .NET languages using a syntax not far from the one available in Java.
public dynamic DynJVM { get; }
Property Value
- dynamic
A dynamic entry point to interact with JVM
Examples
To instantiate a new JVM String you can use a code like:
var myStr = DynJVM.String.@new();
For an array:
var myArray = DynJVM.ArrayList.@new();
myArray.add(1);
myArray.add(2);
In general this property make the operations against the JVM very simple.
Remarks
It is marked with dynamic keyword. If during runtime an RuntimeBinderException is thrown, check the code to verify if there is a correspondance on Java side.
Possible problems come from:
- A not imported package
- A not existent class
- A type in code
- A missing method on the requested Java class
EnableCriticalMethods
Always enable/disable use of critical methods within JNI interface, to get/set native type arrays, single wrapper for EnableCriticalMethodsOnGet and EnableCriticalMethodsOnSet
[Obsolete("Use the property available in Management property", true)]
public bool? EnableCriticalMethods { get; set; }
Property Value
- bool?
EnableCriticalMethodsOnGet
Always enable/disable use of critical methods, within JNI interface, to get native type arrays
[Obsolete("Use the property available in Management property", true)]
public bool? EnableCriticalMethodsOnGet { get; set; }
Property Value
- bool?
EnableCriticalMethodsOnGetThreshold
Enable/Disable use of critical methods, within JNI interface, to get native type arrays if the length is over the EnableCriticalMethodsOnSetThreshold. Default is MaxValue
[Obsolete("Use the property available in Management property", true)]
public int EnableCriticalMethodsOnGetThreshold { get; set; }
Property Value
EnableCriticalMethodsOnSet
Always enable/disable use of critical methods, within JNI interface, to set native type arrays
[Obsolete("Use the property available in Management property", true)]
public bool? EnableCriticalMethodsOnSet { get; set; }
Property Value
- bool?
EnableCriticalMethodsOnSetThreshold
Enable/Disable use of critical methods, within JNI interface, to set native type arrays if the length is over the EnableCriticalMethodsOnSetThreshold. Default is MaxValue
[Obsolete("Use the property available in Management property", true)]
public int EnableCriticalMethodsOnSetThreshold { get; set; }
Property Value
EnableDebug
Enables Debug
public virtual bool EnableDebug { get; }
Property Value
EnableNativeAccess
true to enable native access as defined in https://openjdk.org/jeps/472, default value is false for compatibility with JDK 11.
public virtual bool EnableNativeAccess { get; }
Property Value
FeatureLevel
Reports the feature level of the JVM in use
[Obsolete("Use the property available in Management property", true)]
public int FeatureLevel { get; }
Property Value
Remarks
-1 means the feature level was not identified
FilteredArgs
The remaining arguments after applied the parsing of JCOBridge arguments. Useful when invoked application does not accept arguments related to JCOBridge.
public static string[] FilteredArgs { get; }
Property Value
- string[]
GlobalHeapSize
Sets the global heap size
public virtual string GlobalHeapSize { get; }
Property Value
Globalize
public virtual bool Globalize { get; }
Property Value
InitialHeapSize
Sets the initial heap size
public virtual string InitialHeapSize { get; }
Property Value
IsContainer
Return true if the running environment is a container
public static bool IsContainer { get; }
Property Value
JDKHome
The path where is located the JRE of the installed JDK
public virtual string JDKHome { get; }
Property Value
JNIOutputFile
The path where the JNI verbose info will be written. The file will be opened in append mode.
public virtual string JNIOutputFile { get; }
Property Value
JNIVerbosity
Sets the verbosity of the JNI interface. See oracle documentation.
public virtual string JNIVerbosity { get; }
Property Value
JVM
The entry point for direct JVM operations. Use DynJVM to write code like you made in Java
public IJVMWrapperDirect JVM { get; }
Property Value
JVMOptions
The options to pass to the JVM when a JVM will be created
public virtual IEnumerable<KeyValuePair<string, string>> JVMOptions { get; }
Property Value
JVMPackages
The list of packages on startup. Further packages can be added later
public virtual IEnumerable<string> JVMPackages { get; }
Property Value
JVMPath
The path to the JRE ennvironment or full path to (jvm.dll/libjvm.so). If not set the library try to find a suitable version on the system.
public virtual string JVMPath { get; }
Property Value
JVMStats
The entry point for JVM statistics
protected IJVMWrapperStatistics JVMStats { get; }
Property Value
JavaDebugOpts
Java Debug options used if EnableDebug is true
public virtual string JavaDebugOpts { get; }
Property Value
JavaDebugPort
Java Debug Port
public virtual short JavaDebugPort { get; }
Property Value
JmxPort
The JMX Port to use
public virtual short? JmxPort { get; }
Property Value
LicensePath
The path where is located the license file
public virtual string LicensePath { get; }
Property Value
Management
The entry point for management operations
public IJVMWrapperManagement Management { get; }
Property Value
ModulePath
The starting JVM module path. Further path can be added later.
public virtual string ModulePath { get; }
Property Value
Remarks
It is not the same modulepath switch available in CLI. No wildcards expansion is made at this level.
RemoteBridge
Direct accessor to the JCOBridge class in the JVM context
protected IJavaType RemoteBridge { get; }
Property Value
RemoteJCOBridge
Dynamic accessor to the JCOBridge class in the JVM context
protected dynamic RemoteJCOBridge { get; }
Property Value
- dynamic
A dynamic entry point to interact with JCOBridge class within JVM context
Remarks
It is marked with dynamic keyword. If during runtime an RuntimeBinderException is thrown, check the code to verify if there is a correspondance on Java side.
Possible problems come from:
- A typo in code
- A missing method on the Java-side JCOBridge class
SuppressFinalize
true to suppress finalization of the class instance inherited from SetupJVMWrapper when the instance is created using CreateGlobalInstance(), the instance is globalized using Globalize(IJVMBridgeCore, bool). Default value is true.
public virtual bool SuppressFinalize { get; }
Property Value
Methods
~SetupJVMWrapper()
Finalize an instance of SetupJVMWrapper
protected ~SetupJVMWrapper()
GetCLRGlobal(string)
Get previously registered object from CLR global mapper
[Obsolete("Use the method available in Management property", true)]
public object GetCLRGlobal(string key)
Parameters
key
stringThe key to identify the registered object
Returns
GetJCGraphicContainer(IJavaObject, bool)
Requests to allocate a remote graphic container to host the Component in graphicObject
[Obsolete("Use the method available in Management property", true)]
public IJCGraphicContainer GetJCGraphicContainer(IJavaObject graphicObject, bool isWPF)
Parameters
graphicObject
IJavaObjectThe object, in the form of IJavaObject, to be inserted in the grphical hierarchy
isWPF
booltrue if the request come from a WPF host application, false for WinForms host application
Returns
- IJCGraphicContainer
A IJCGraphicContainer reference to the newly allocated container
Remarks
This version supports a single JCGraphicContainer needing direct management of Windows Message Pump, other JCGraphicContainer must internally manages message pump, setting the property IsRemoteManaged to true.
GetJCGraphicContainer(string, bool)
Requests to allocate a remote graphic container to host the Component with class name className
[Obsolete("Use the method available in Management property", true)]
public IJCGraphicContainer GetJCGraphicContainer(string className, bool isWPF)
Parameters
className
stringThe name of the class to allocate and insert in the grphical hierarchy
isWPF
booltrue if the request come from a WPF host application, false for WinForms host application
Returns
- IJCGraphicContainer
A IJCGraphicContainer reference to the newly allocated container
Remarks
This version supports a single JCGraphicContainer needing direct management of Windows Message Pump, other JCGraphicContainer must internally manages message pump, setting the property IsRemoteManaged to true.
GetJVMGlobal(string)
Get previously registered IJavaObject from JVM global mapper
[Obsolete("Use the method available in Management property", true)]
public IJavaObject GetJVMGlobal(string key)
Parameters
key
stringThe key to identify the registered object
Returns
- IJavaObject
Previously registered global IJavaObject
GetListener(IJavaObject)
Returns the IJVMBridgeBase listener reference associated to the JVM reference
[Obsolete("Use the method available in Management property", true)]
public IJVMBridgeBase GetListener(IJavaObject eventListener)
Parameters
eventListener
IJavaObjectThe JVM reference associated to the IJVMBridgeBase
Returns
- IJVMBridgeBase
The IJVMBridgeBase associated to the
eventListener
GetMainClasses(Assembly)
Retrieve all Main-Class from the assembly
[Obsolete("Use the method available in JCOBridge static class", true)]
public static IDictionary<string, Type> GetMainClasses(Assembly assembly)
Parameters
Returns
- IDictionary<string, Type>
A IDictionary<TKey, TValue> containing the name of the Main-Class and its Type
ImportPackage(string)
Imports a Java package to be used within the program
[Obsolete("Use the method available in JVM property", true)]
public void ImportPackage(string packageName)
Parameters
packageName
stringThe package in the form of java.lang, java.util, etc.
Examples
To add package search use a code like:
// the following code is the Java equivalent of import java.lang.*;
ImportPackage("java.lang");
InitializeListener(IJVMBridgeBase)
Request the initialization of the Listener from the JVM. The listener
is a new class which inherits from JVMBridgeListener or JVMBridgeListener
[Obsolete("Use the method available in Management property", true)]
public void InitializeListener(IJVMBridgeBase listener)
Parameters
listener
IJVMBridgeBaseThe IJVMBridgeBase listener reference to be initialized
Launch(Type, params string[])
Launch the type
with the args
arguments
[Obsolete("Use the method available in JCOBridge static class", true)]
public static void Launch(Type type, params string[] args)
Parameters
type
TypeThe Type extending IJVMBridgeMain
args
string[]The arguments of the main method
Launch<TClass>(params string[])
Launch the TClass
with the args
arguments
[Obsolete("Use the method available in JCOBridge static class", true)]
public static void Launch<TClass>(params string[] args) where TClass : IJVMBridgeMain
Parameters
args
string[]The arguments of the main method
Type Parameters
TClass
A type which is defined as Main-Class
PostInitialization()
Override the method to manage post initialization step
protected virtual void PostInitialization()
PreInitialization(ref string, ref Version)
Override the method to setup some information, this is the first virtual method invoked: some settings can be applied here like SetEventOrExceptionHandler(EventHandler<EventOrExceptionEventArgs>)
protected virtual void PreInitialization(ref string scopeOn, ref Version scopeOnVersion)
Parameters
scopeOn
stringThe value to return to override the value of MASES.JCOBridge.C2JBridge.SetupJVMWrapper.ScopedOn
scopeOnVersion
VersionThe value to return to override the value of MASES.JCOBridge.C2JBridge.SetupJVMWrapper.ScopedOnVersion
ProcessCommandLine()
Process command line arguments
protected virtual string[] ProcessCommandLine()
Returns
- string[]
The filtered residual arguments
RegisterCLRGlobal(string, object)
Register the object into the global CLR mapper.
[Obsolete("Use the method available in Management property", true)]
public void RegisterCLRGlobal(string key, object obj)
Parameters
ReleaseJCGraphicContainer(IJCGraphicContainer)
Reelase a IJCGraphicContainer from the JVM
[Obsolete("Use the method available in Management property", true)]
public void ReleaseJCGraphicContainer(IJCGraphicContainer container)
Parameters
container
IJCGraphicContainerThe IJCGraphicContainer to be released
ReleaseListener(IJVMBridgeBase)
Release a IJVMBridgeBase listener reference from the JVM
[Obsolete("Use the method available in Management property", true)]
public void ReleaseListener(IJVMBridgeBase listener)
Parameters
listener
IJVMBridgeBaseThe IJVMBridgeBase listener reference to be released
UnregisterCLRGlobal(string)
Unregister the object from the global CLR mapper.
[Obsolete("Use the method available in Management property", true)]
public void UnregisterCLRGlobal(string key)
Parameters
key
stringThe key to identify the registered
UnwrapAndDemonizeOn<T>(ParameterizedThreadStart, object, ApartmentState)
Creates and unwrap the JVM instance as daemon
public T UnwrapAndDemonizeOn<T>(ParameterizedThreadStart handler, object arg = null, ApartmentState apartment = ApartmentState.STA) where T : SetupJVMWrapper
Parameters
handler
ParameterizedThreadStartAn handler to the function to be invoked
arg
objectThe argument for
handler
. Default is null.apartment
ApartmentStateThe ApartmentState to be used when the thread is started
Returns
- T
An instance of
T
Type Parameters
T
The class extending SetupJVMWrapper
Remarks
apartment
is valid only on Windows
UnwrapOn<T>(ParameterizedThreadStart, object, ApartmentState)
Creates and unwrap the JVM instance
public T UnwrapOn<T>(ParameterizedThreadStart handler, object arg = null, ApartmentState apartment = ApartmentState.STA) where T : SetupJVMWrapper
Parameters
handler
ParameterizedThreadStartAn handler to the function to be invoked
arg
objectThe argument for
handler
. Default is null.apartment
ApartmentStateThe ApartmentState to use to start the thread
Returns
- T
An instance of
T
Type Parameters
T
The class extending SetupJVMWrapper