Compiling and Installing the Java Interface JIPOPT

based on documentation by Rafael de Pelegrini Soares12


JIPOPT uses the Java Native Interface (JNI), which is a programming framework that allows Java code running in the Java Virtual Machine (JVM) to call and be called by native applications and libraries written in languages such as C and C++. JIPOPT requires Java 5 or higher.

After building and installing IPOPT, the JIPOPT interface can be build by setting the environment variable JAVA_HOME to the directory that contains your JDK, changing to the JIPOPT directory in your IPOPT build, and issuing make, e.g.,

  export JAVA_HOME=/usr/lib/jvm/java-1.5.0
  cd $IPOPTDIR/build/Ipopt/contrib/JavaInterface
  make

This will generate the Java class org/coinor/Ipopt.class, which you will need to make available in your Java code (i.e., add $IPOPTDIR/build/Ipopt/contrib/JavaInterface to your CLASSPATH) and the shared object lib/libjipopt.so (on Linux/UNIX) or lib/libjipopt.dylib (on Mac OS X) or the DLL lib/jipopt.dll (on Windows). In order to test your JIPOPT library you can run two example problems by issuing the command make test inside the JIPOPT directory.

NOTE: The JIPOPT build procedure currently cannot deal with spaces in the path to the JDK. If you are on Windows and have Java in a path like C:\Program Files\Java, try setting JAVA_HOME to the DOS equivalent C:\Progra~1 (or similar).

NOTE: JIPOPT needs to be able to load the IPOPT library dynamically at runtime. Therefore, IPOPT must have been compiled with the -fPIC compiler flag. While per default, an Ipopt shared library is compiled with this flag, for a configuration of IPOPT in debug mode (-enable-debug) or as static library (-disable-shared), the configure flag -with-pic need to be used to enable compilation with -fPIC.



Footnotes

... Soares12
VRTech Industrial Technologies