spawnIfNotExists static method
Same as spawn but if a JVM exists, returns silently instead of
throwing JvmExistsError
.
If the options are different than that of existing VM, the existing VM's options will remain in effect.
Implementation
static bool spawnIfNotExists({
String? dylibDir,
List<String> jvmOptions = const [],
List<String> classPath = const [],
bool ignoreUnrecognized = false,
int jniVersion = JniVersions.JNI_VERSION_1_6,
}) =>
using((arena) {
_dylibDir = dylibDir;
final jvmArgs = _createVMArgs(
options: jvmOptions,
classPath: classPath,
version: jniVersion,
dylibPath: dylibDir,
ignoreUnrecognized: ignoreUnrecognized,
allocator: arena,
);
final status = _bindings.SpawnJvm(jvmArgs);
if (status == JniErrorCode.JNI_OK) {
return true;
} else if (status == DART_JNI_SINGLETON_EXISTS) {
return false;
} else {
throw JniError.of(status);
}
});