Class Chemmisol

java.lang.Object
ummisco.gama.chemmisol.Chemmisol

public class Chemmisol extends Object
Main Chemmisol helper class, that defines static methods to load the native chemmisol-cpp library from different places.

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 a static { } block.

Loading from system files

Loads the chemmisol 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 Details

  • 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 the chemmisol library from the resource_path_to_chemmisol resource folder of the clazz1 class, and loads the chemmisol-java library from the resource_path_to_chemmisol_java resource folder of the clazz2 class.

      Libraries are loaded from resource/path/<library_name> where <library_name> is the system dependent file name obtained from System.mapLibraryName("chemmisol") and System.mapLibraryName("chemmisol-java").

      Parameters:
      clazz1 - Class from which the chemmisol library is loaded.
      resource_path_to_chemmisol - Path to the resource folder containing the chemmisol library. Should generally be specified as a relative path from clazz1.
      clazz2 - Class from which the chemmisol-java library is loaded.
      resource_path_to_chemmisol_java - Path to the resource folder containing the chemmisol-java library. Should generally be specified as a relative path from clazz2.
      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 the chemmisol and chemmisol-java libraries from the resource_path resource folder of the clazz class.

      Libraries are loaded from resource/path/<library_name> where <library_name> is the system dependent file name obtained from System.mapLibraryName("chemmisol") and System.mapLibraryName("chemmisol-java").

      Parameters:
      clazz - Class from which the chemmisol and chemmisol-java libraries are loaded.
      resource_path - Path to the resource folder containing the chemmisol and chemmisol-java libraries. Should generally be specified as a relative path from clazz.
      Throws:
      IOException - if one of the native library cannot be loaded from the specified resource path.
    • loadChemmisolLibrariesFromResource

      public static void loadChemmisolLibrariesFromResource(Class<?> clazz) throws IOException
      Loads the chemmisol and chemmisol-java libraries from the resources of the specified class.

      Libraries are loaded from the file name <library_name>, obtained from System.mapLibraryName("chemmisol") and System.mapLibraryName("chemmisol-java").

      Parameters:
      clazz - Class from which the chemmisol and chemmisol-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 the chemmisol and chemmisol-java libraries from the file system. Libraries are loaded from /resource/path/<library_name> where <library_name> is the system dependent file name obtained from System.mapLibraryName("chemmisol") and System.mapLibraryName("chemmisol-java").
      Parameters:
      path_to_chemmisol_library - Path to the folder containing the chemmisol library.
      path_to_chemmisol_java_library - Path to the folder containing the chemmisol-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 the chemmisol and chemmisol-java libraries from the file system.

      Libraries are loaded from /resource/path/<library_name> where <library_name> is the system dependent file name obtained from System.mapLibraryName("chemmisol") and System.mapLibraryName("chemmisol-java").

      Parameters:
      path_to_chemmisol - Path to the folder containing the chemmisol and chemmisol-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 the chemmisol and chemmisol-java libraries from the path represented by the property named lib_directory_property in the project_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 the chemmisol and chemmisol-java libraries.
      Throws:
      IOException - if an error occurs when loading the properties file.
      UnsatisfiedLinkError - if an error occurs when loading the native library.