Class Chemmisol
In order to properly load the chemmisol library, it is necessary to identify
the location of the compiled chemmisol and chemmisol-java
libraries. The native chemmisol library corresponds to the base chemmisol-cpp C++ library,
while chemmisol-java corresponds to JNI code contained in the
chemmisol-java/src/main/cpp directory of the chemmisol-java repository. See
the README file of the chemmisol-java project for
details about how to build and find those libraries.
Library files are typically named libchemmisol.so and
libchemmisol-java.so on UNIX platforms and libchemmisol.dll and
libchemmisol-java.dll on Windows platforms.
Both libraries can be loaded either from the file system or from Java resources. How resources are bundled is project and build system dependent (see for example maven-jar-plugin or how eclipse manages the Java Build Path).
However, how resources are accessed is "location independent". This means that for methods that load libraries from resources, the paths to resources can be specified relatively to the class from which they are loaded.
Examples
The simplest way to load the Chemmisol libraries is generally to call one of the provided method from astatic { } block.
Loading from system files
Loads thechemmisol and chemmisol-java libraries from the
/usr/local/lib system directory:
import ummisco.gama.chemmisol.Chemmisol;
public class MyClass {
static {
try {
Chemmisol.loadChemmisolLibrariesFromFiles("/usr/local/lib");
} catch (UnsatisfiedLinkError e) {
System.err.println(e);
}
}
}
Loading from class resources
Assuming the project is set up as a Maven project with the following standard directory layout:
- src
- main
- java
- my
- package
- MyClass.java
- resources
- my
- package
- lib
- libchemmisol.so
- libchemmisol-java.so
The library can be loaded from project resources as follows:
package my.package;
public static class MyClass {
static {
try {
Chemmisol.loadChemmisolLibrariesFromResource("lib");
} catch (UnsatisfiedLinkError e) {
System.err.println(e);
}
}
}
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidloadChemmisolLibrariesFromFile(Path path_to_chemmisol) Loads thechemmisolandchemmisol-javalibraries from the file system.static voidloadChemmisolLibrariesFromFiles(Path path_to_chemmisol_library, Path path_to_chemmisol_java_library) Loads thechemmisolandchemmisol-javalibraries from the file system.static voidloadChemmisolLibrariesFromProperties(Class<?> clazz, String project_properties, String lib_directory_property) Loads thechemmisolandchemmisol-javalibraries from the path represented by the property namedlib_directory_propertyin theproject_propertiesfile loaded from the specified class.static voidloadChemmisolLibrariesFromResource(Class<?> clazz) Loads thechemmisolandchemmisol-javalibraries from the resources of the specified class.static voidloadChemmisolLibrariesFromResource(Class<?> clazz, String resource_path) Loads thechemmisolandchemmisol-javalibraries from theresource_pathresource folder of theclazzclass.static voidloadChemmisolLibrariesFromResource(Class<?> clazz1, String resource_path_to_chemmisol, Class<?> clazz2, String resource_path_to_chemmisol_java) Loads thechemmisollibrary from theresource_path_to_chemmisolresource folder of theclazz1class, and loads thechemmisol-javalibrary from theresource_path_to_chemmisol_javaresource folder of theclazz2class.
-
Field Details
-
CHEMMISOL
chemmisol library name.- See Also:
-
CHEMMISOL_JAVA
chemmisol-java library name.- See Also:
-
-
Constructor Details
-
Chemmisol
public Chemmisol()
-
-
Method Details
-
loadChemmisolLibrariesFromResource
public static void loadChemmisolLibrariesFromResource(Class<?> clazz1, String resource_path_to_chemmisol, Class<?> clazz2, String resource_path_to_chemmisol_java) throws IOException Loads thechemmisollibrary from theresource_path_to_chemmisolresource folder of theclazz1class, and loads thechemmisol-javalibrary from theresource_path_to_chemmisol_javaresource folder of theclazz2class.Libraries are loaded from
resource/path/<library_name>where<library_name>is the system dependent file name obtained fromSystem.mapLibraryName("chemmisol")andSystem.mapLibraryName("chemmisol-java").- Parameters:
clazz1- Class from which thechemmisollibrary is loaded.resource_path_to_chemmisol- Path to the resource folder containing thechemmisollibrary. Should generally be specified as a relative path fromclazz1.clazz2- Class from which thechemmisol-javalibrary is loaded.resource_path_to_chemmisol_java- Path to the resource folder containing thechemmisol-javalibrary. Should generally be specified as a relative path fromclazz2.- Throws:
IOException- if one of the native library cannot be loaded from the specified resource paths.
-
loadChemmisolLibrariesFromResource
public static void loadChemmisolLibrariesFromResource(Class<?> clazz, String resource_path) throws IOException Loads thechemmisolandchemmisol-javalibraries from theresource_pathresource folder of theclazzclass.Libraries are loaded from
resource/path/<library_name>where<library_name>is the system dependent file name obtained fromSystem.mapLibraryName("chemmisol")andSystem.mapLibraryName("chemmisol-java").- Parameters:
clazz- Class from which thechemmisolandchemmisol-javalibraries are loaded.resource_path- Path to the resource folder containing thechemmisolandchemmisol-javalibraries. Should generally be specified as a relative path fromclazz.- Throws:
IOException- if one of the native library cannot be loaded from the specified resource path.
-
loadChemmisolLibrariesFromResource
Loads thechemmisolandchemmisol-javalibraries from the resources of the specified class.Libraries are loaded from the file name
<library_name>, obtained fromSystem.mapLibraryName("chemmisol")andSystem.mapLibraryName("chemmisol-java").- Parameters:
clazz- Class from which thechemmisolandchemmisol-javalibraries are loaded.- Throws:
IOException- if one of the native library cannot be loaded from the resources of the class.
-
loadChemmisolLibrariesFromFiles
public static void loadChemmisolLibrariesFromFiles(Path path_to_chemmisol_library, Path path_to_chemmisol_java_library) throws UnsatisfiedLinkError Loads thechemmisolandchemmisol-javalibraries from the file system. Libraries are loaded from/resource/path/<library_name>where<library_name>is the system dependent file name obtained fromSystem.mapLibraryName("chemmisol")andSystem.mapLibraryName("chemmisol-java").- Parameters:
path_to_chemmisol_library- Path to the folder containing thechemmisollibrary.path_to_chemmisol_java_library- Path to the folder containing thechemmisol-javalibrary.- Throws:
UnsatisfiedLinkError- if an error occurs when loading the native library.
-
loadChemmisolLibrariesFromFile
public static void loadChemmisolLibrariesFromFile(Path path_to_chemmisol) throws UnsatisfiedLinkError Loads thechemmisolandchemmisol-javalibraries from the file system.Libraries are loaded from
/resource/path/<library_name>where<library_name>is the system dependent file name obtained fromSystem.mapLibraryName("chemmisol")andSystem.mapLibraryName("chemmisol-java").- Parameters:
path_to_chemmisol- Path to the folder containing thechemmisolandchemmisol-javalibraries.- Throws:
UnsatisfiedLinkError- if an error occurs when loading the native library.
-
loadChemmisolLibrariesFromProperties
public static void loadChemmisolLibrariesFromProperties(Class<?> clazz, String project_properties, String lib_directory_property) throws IOException, UnsatisfiedLinkError Loads thechemmisolandchemmisol-javalibraries from the path represented by the property namedlib_directory_propertyin theproject_propertiesfile loaded from the specified class.- Parameters:
clazz- Class from which the project_properties file is loaded as a resource.project_properties- Name of the project properties resource file.lib_directory_property- Name of the property representing the folder containing thechemmisolandchemmisol-javalibraries.- Throws:
IOException- if an error occurs when loading the properties file.UnsatisfiedLinkError- if an error occurs when loading the native library.
-