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.soThe 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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
loadChemmisolLibrariesFromFile
(Path path_to_chemmisol) Loads thechemmisol
andchemmisol-java
libraries from the file system.static void
loadChemmisolLibrariesFromFiles
(Path path_to_chemmisol_library, Path path_to_chemmisol_java_library) Loads thechemmisol
andchemmisol-java
libraries from the file system.static void
loadChemmisolLibrariesFromProperties
(Class<?> clazz, String project_properties, String lib_directory_property) Loads thechemmisol
andchemmisol-java
libraries from the path represented by the property namedlib_directory_property
in theproject_properties
file loaded from the specified class.static void
loadChemmisolLibrariesFromResource
(Class<?> clazz) Loads thechemmisol
andchemmisol-java
libraries from the resources of the specified class.static void
loadChemmisolLibrariesFromResource
(Class<?> clazz, String resource_path) Loads thechemmisol
andchemmisol-java
libraries from theresource_path
resource folder of theclazz
class.static void
loadChemmisolLibrariesFromResource
(Class<?> clazz1, String resource_path_to_chemmisol, Class<?> clazz2, String resource_path_to_chemmisol_java) Loads thechemmisol
library from theresource_path_to_chemmisol
resource folder of theclazz1
class, and loads thechemmisol-java
library from theresource_path_to_chemmisol_java
resource folder of theclazz2
class.
-
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 thechemmisol
library from theresource_path_to_chemmisol
resource folder of theclazz1
class, and loads thechemmisol-java
library from theresource_path_to_chemmisol_java
resource folder of theclazz2
class.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 thechemmisol
library is loaded.resource_path_to_chemmisol
- Path to the resource folder containing thechemmisol
library. Should generally be specified as a relative path fromclazz1
.clazz2
- Class from which thechemmisol-java
library is loaded.resource_path_to_chemmisol_java
- Path to the resource folder containing thechemmisol-java
library. 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 thechemmisol
andchemmisol-java
libraries from theresource_path
resource folder of theclazz
class.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 thechemmisol
andchemmisol-java
libraries are loaded.resource_path
- Path to the resource folder containing thechemmisol
andchemmisol-java
libraries. 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 thechemmisol
andchemmisol-java
libraries 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 thechemmisol
andchemmisol-java
libraries 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 thechemmisol
andchemmisol-java
libraries 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 thechemmisol
library.path_to_chemmisol_java_library
- Path to the folder containing thechemmisol-java
library.- Throws:
UnsatisfiedLinkError
- if an error occurs when loading the native library.
-
loadChemmisolLibrariesFromFile
public static void loadChemmisolLibrariesFromFile(Path path_to_chemmisol) throws UnsatisfiedLinkError Loads thechemmisol
andchemmisol-java
libraries 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 thechemmisol
andchemmisol-java
libraries.- 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 thechemmisol
andchemmisol-java
libraries from the path represented by the property namedlib_directory_property
in theproject_properties
file 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 thechemmisol
andchemmisol-java
libraries.- Throws:
IOException
- if an error occurs when loading the properties file.UnsatisfiedLinkError
- if an error occurs when loading the native library.
-