Java and jSMILE

<< Click to Display Table of Contents >>

Navigation:  Platforms and wrappers >

Java and jSMILE

jSMILE is compatible with JDK 8 and newer. See the Maven section below for information about using jSMILE in a Maven-based project, including the location of BayesFusion's Maven repository and POM integration with jSMILE's native library.

jSMILE consists of two parts: the JAR file and the native library, the latter being specific to your operating system. The JAR file, named jsmile-x.y.z.jar (where x.y.z is the version number), can be used like any other Java JAR.

The native library is used by the JAR code through the Java Native Interface (JNI). Its file name is platform-dependent:

jsmile.dll on Windows

jsmile.so on Linux

jsmile.jnilib on macOS

In the static initializer of the smile.Wrapper class, jSMILE attempts to load its native library. If the jsmile.native.library system property is set, jSMILE calls System.load using the property value as the full path to the native library (relative paths are not allowed). Otherwise, System.loadLibrary is used. In this case, the native library must be located in one of the directories specified by the java.library.path property. Note that java.library.path cannot be modified once the JVM is running, but jsmile.native.library can be set dynamically with a call to System.setProperty.

Your license key should be pasted into the source code of your program.

The classes defined in jSMILE are located in smile and smile.learning packages. There are two types of classes:

simple objects with public data members

wrappers for C++ objects from the SMILE library

The second group of classes, which includes smile.Network, derives from smile.Wrapper. Each instance of these classes has an associated C++ object, which is deallocated either by the Java object’s finalizer or by an explicit call to Wrapper.Dispose. To ensure timely deallocation of C++ resources, Dispose should be called as soon as the program no longer needs the object. If Dispose is not called, deallocation occurs during garbage collection in the finalizer. Java's try-with-resources statement can be used:

try (Network net = new Network()) {

    // use the net object in this scope

}