Platforms to show: All Mac Windows Linux Cross-Platform

Back to JavaVMMBS class.

JavaVMMBS.Constructor(path as folderitem)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 8.5 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Initializes the Java virtual machine.

This is a convenience function which initializes the java with version=JNI_VERSION_1_4 and no options except the specified path.
The path can be a folderitem pointing to a jar file or a folder with class files.

This method raises UnsupportedOperationException with error about missing CreateJavaVM function if there is no Java found. Either because it is not installed or the bit number (32 vs. 64) does not match.

Since version 16.5 the plugin will no longer raise exception if an existing JavaVM was found. In that case we use that JavaVM and return normally. Lasterror will be set to -5 which indicates this. In that case your options and paths are not passed to VM.

See also:

JavaVMMBS.Constructor(path as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 8.5 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Initializes the Java virtual machine.

This is a convenience function which initializes the java engine with version=JNI_VERSION_1_4 and no options except the specified path.
The path can be a path pointing to a jar file or a folder with class files. If you use more than one path, you need to separate them with ";". Seems like on Mac OS X and Linux the separator is ":".

This method raises UnsupportedOperationException with error about missing CreateJavaVM function if there is no Java found. Either because it is not installed or the bit number (32 vs. 64) does not match.

Since version 16.5 the plugin will no longer raise exception if an existing JavaVM was found. In that case we use that JavaVM and return normally. Lasterror will be set to -5 which indicates this. In that case your options and paths are not passed to VM.

See also:

JavaVMMBS.Constructor(version as Integer, options() as string, ignoreUnrecognizedOptions as boolean)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 8.5 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Initializes the java virtual machine.

Only one VM can run at a time with this plugin.
You can specify whatever command line options you need in the options array.
Version must be one of the JNI_VERSION_1_x constants.

A note for Mac OS X and Java versions:

To specify the current preferred JDK in a family of JVM's, say the 1.5.x family, applications should set the environment variable JAVA_JVM_VERSION to 1.5, and then pass JNI_VERSION_1_4 into JNI_CreateJavaVM as the vm_args.version. To get a specific Java 1.5 JVM, say Java 1.5.0, set the environment variable JAVA_JVM_VERSION to 1.5.0. For Java 1.6 it will be the same in that applications will need to set the environment variable JAVA_JVM_VERSION to 1.6 to specify the current preferred 1.6 Java VM, and to get a specific Java 1.6 JVM, say Java 1.6.1, set the environment variable JAVA_JVM_VERSION to 1.6.1.

To make this sample bring up the current preferred 1.5 JVM, set the environment variable JAVA_JVM_VERSION to 1.5 before calling JNI_CreateJavaVM as shown below. Applications must currently check for availability of JDK 1.5 before requesting it. If your application requires JDK 1.5 and it is not found, it is your responsibility to report an error to the user. To verify if a JVM is installed, check to see if the symlink, or directory exists for the JVM in /System/Library/Frameworks/JavaVM.framework/Versions/ before setting the environment variable JAVA_JVM_VERSION.

If the environment variable JAVA_JVM_VERSION is not set, and JNI_VERSION_1_4 is passed into JNI_CreateJavaVM as the vm_args.version, JNI_CreateJavaVM will return the current preferred JDK. Java 1.4.2 is the preferred JDK as of the release of this sample and the release of Mac OS X 10.4.

Useful option strings:
"-verbose:jni"show debug output on the console
"-Xms256M"initial memory
"-Xmx512M" maximum memory

This method raises UnsupportedOperationException with error about missing CreateJavaVM function if there is no Java found. Either because it is not installed or the bit number (32 vs. 64) does not match.

Since version 16.5 the plugin will no longer raise exception if an existing JavaVM was found. In that case we use that JavaVM and return normally. Lasterror will be set to -5 which indicates this. In that case your options and paths are not passed to VM.

If you get error 126 on Windows, maybe MSVCR100.DLL is missing. So install Visual Studio 2010 runtime libraries. You can download them from Microsoft website. Do not download them from other websites spreading malware!

See also:

JavaVMMBS.Constructor(version as Integer, options() as string, path as folderitem, ignoreUnrecognizedOptions as boolean)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 8.5 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Initializes the Java virtual machine.
Example
Var JarPath as folderitem = specialfolder.desktop.child("test.jar")
Var options() as string

options.append "-Xms256M"
options.append "-Xmx512M"

Var v as new JavaVMMBS( JavaVMMBS.JNI_VERSION_1_4, options, JarPath, false)

This is a convenience function which initializes the java engine with adding the given path to the options.

Only one VM can run at a time with this plugin.
You can specify whatever command line options you need in the options array.
Version must be one of the JNI_VERSION_1_x constants.
The path can be a folderitem pointing to a jar file or a folder with class files.

Useful option strings:
"-verbose:jni"show debug output on the console
"-Xms256M"initial memory
"-Xmx512M" maximum memory

This method raises UnsupportedOperationException with error about missing CreateJavaVM function if there is no Java found. Either because it is not installed or the bit number (32 vs. 64) does not match.

Since version 16.5 the plugin will no longer raise exception if an existing JavaVM was found. In that case we use that JavaVM and return normally. Lasterror will be set to -5 which indicates this. In that case your options and paths are not passed to VM.

See also:

JavaVMMBS.Constructor(version as Integer, options() as string, path as string, ignoreUnrecognizedOptions as boolean)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 8.5 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Initializes the java virtual machine.

This is a convenience function which initializes the java engine with adding the given path to the options.

Only one VM can run at a time with this plugin.
You can specify whatever command line options you need in the options array.
Version must be one of the JNI_VERSION_1_x constants.
The path can be a path pointing to a jar file or a folder with class files. If you use more than one path, you need to separate them with ";". Seems like on Mac OS X and Linux the separator is ":".

Useful option strings:
"-verbose:jni"show debug output on the console
"-Xms256M"initial memory
"-Xmx512M" maximum memory

This method raises UnsupportedOperationException with error about missing CreateJavaVM function if there is no Java found. Either because it is not installed or the bit number (32 vs. 64) does not match.

Since version 16.5 the plugin will no longer raise exception if an existing JavaVM was found. In that case we use that JavaVM and return normally. Lasterror will be set to -5 which indicates this. In that case your options and paths are not passed to VM.

See also:

JavaVMMBS.DefineClass(name as string, Data as MemoryBlock) as JavaClassMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 20.3 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Loads a class from a buffer of raw class data.

Returns nil in case of error or valid class object on success.
You may want to load a class file and pass it here as String or MemoryBlock.
To read jar file, you can use our archive classes to expand zip archives.

See also:

JavaVMMBS.DefineClass(name as string, Data as String) as JavaClassMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 20.3 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Loads a class from a buffer of raw class data.

Returns nil in case of error or valid class object on success.
You may want to load a class file and pass it here as String or MemoryBlock.
To read jar file, you can use our archive classes to expand zip archives.

See also:

JavaVMMBS.FindClass(name as string) as JavaClassMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 4.3 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Searches a class based on the name.
Example
Var e as JavaVMMBS // global
Var c as JavaClassMBS
c=e.FindClass("java/lang/String")

This function loads a locally defined class. It searches the directories and zip files specified by the CLASSPATH environment variable for the class with the specified name.

name: a fully qualified class name (that is, a package name, delimited by "/", followed by the class name). If the name begins with "[" (the array signature character), it returns an array class.

Returns nil on any error.

If your class is not found, it may be possible that it can't be loaded as the jar archive has dependencies to other jar archives.

Some examples using this method:

JavaVMMBS.FreeCurrentThread

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 8.4 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Releases the thread in Java.
Example
Var w as JavaVMMBS // your vm object
w.FreeCurrentThread

The plugin is written to detect if you use it in a thread. But when the thread ends you need to deregister it with the Java runtime.

Some examples using this method:

JavaVMMBS.FromReflectedField(field as JavaObjectMBS) as JavaFieldMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 4.3 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Searchs the field which matches the reflected field object.

JavaVMMBS.FromReflectedMethod(method as JavaObjectMBS) as JavaMethodMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 4.3 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Searchs the method which matches the reflected method object.

JavaVMMBS.IsAssignableFrom(TheSubClass as JavaClassMBS, TheSuperClass as JavaClassMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 4.3 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
True if the class is assignable from the other class.

That means that the sub class is somewhere down the class tree from the super class.

JavaVMMBS.LoadedClasses as JavaClassMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 25.3 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Queries the list of classes.
Example
// show all class names

var vm as JavaVMMBS // your VM
Var arg As New MemoryBlock(8)
Var LoadedClassNames() As String
Var LoadedClasses() As JavaClassMBS = vm.LoadedClasses
For Each c As JavaClassMBS In LoadedClasses
Var jc As JavaClassMBS = c.ObjectClass
Var jm As JavaMethodMBS = jc.GetMethod("getName", "()Ljava/lang/String;")
Var jo As Variant = c.CallObjectMethod(jm, arg)
Var js As JavaStringMBS = jo
Var name As String = js.StringValue
LoadedClassNames.Add name
Next
MessageBox String.FromArray(LoadedClassNames, EndOfLine)

Does not include items from super class.

JavaVMMBS.MonitorEnter(obj as JavaObjectMBS) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 4.3 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Enters the monitor associated with the underlying Java object referred to by obj.

Returns zero on success; otherwise, returns a negative value on failure.

Each Java objects has a monitor associated with it. If the current thread already owns the monitor associated with ref, it increments a counter in the monitor indicating the number of times this thread has entered the monitor. If the monitor associated with ref is not owned by any thread, the current thread becomes the owner of the monitor, setting the entry count of this monitor to 1. If another thread already owns the monitor associated with ref, the current thread waits until the monitor is released, then tries again to gain ownership.

JavaVMMBS.MonitorExit(obj as JavaObjectMBS) as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 4.3 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Releases the monitor.

The current thread must be the owner of the monitor associated with the underlying Java object referred to by ref. The thread decrements the counter indicating the number of times it has entered this monitor. If as a result the value of the counter becomes zero, the current thread releases the montior.

Returns zero on success; otherwise, returns a negative value on failure.

JavaVMMBS.Runtime as JavaRuntimeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 8.5 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Returns the runtime object for the current VM so you can query the memory statistics.

Some examples using this method:

JavaVMMBS.ToReflectedField(TheClass as JavaClassMBS, fieldID as JavaFieldMBS, isStatic as boolean) as JavaObjectMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 4.3 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Creates a new reflected field object for the given field.

JavaVMMBS.ToReflectedMethod(TheClass as JavaClassMBS, methodID as JavaMethodMBS, isStatic as boolean) as JavaObjectMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 4.3 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Creates a new reflected method object for the given method.

JavaVMMBS.Version as Integer

Type Topic Plugin Version macOS Windows Linux iOS Targets
method Java MBS Java Plugin 4.3 ✅ Yes ✅ Yes ✅ Yes ❌ No Desktop, Console & Web
Returns the version of the java engine.

Currently the plugin always uses version 1.4.

Returns the major version number in the higher 16 bits and the minor version number in the lower 16 bits.

In JDK1.1, GetVersion() returns 0x00010001.

The items on this page are in the following plugins: MBS Java Plugin.


The biggest plugin in space...