2009-03-23 02:13:53 +00:00
|
|
|
Open Babel for Java
|
|
|
|
|
-------------------
|
2006-12-15 15:36:18 +00:00
|
|
|
|
2009-09-21 11:12:00 +00:00
|
|
|
This directory contains a compiled Java jar file with SWIG-generated
|
|
|
|
|
interface classes for using the Open Babel C++ library from Java or from any
|
|
|
|
|
other language that runs on the JVM such as Jython or JRuby.
|
2006-12-15 15:36:18 +00:00
|
|
|
|
2007-04-13 18:57:13 +00:00
|
|
|
The Open Babel wiki pages on Java give information on compiling and
|
|
|
|
|
running Java programs with Open Babel:
|
2010-10-10 01:24:39 +00:00
|
|
|
http://openbabel.org/wiki/Java
|
2007-04-13 18:57:13 +00:00
|
|
|
|
|
|
|
|
*** Linux Compilation
|
2006-12-15 15:36:18 +00:00
|
|
|
|
2009-03-23 02:13:53 +00:00
|
|
|
First of all, set some environment variables (remember to change the paths to correspond to your system):
|
2009-09-21 11:12:00 +00:00
|
|
|
$ export JAVA_HOME=/home/noel/Tools/jdk1.5.0_15
|
2019-10-11 14:34:29 +09:00
|
|
|
$ export OB_JAVADIR=/home/noel/Tools/openbabel-3.0.0/scripts/java
|
2009-03-23 02:13:53 +00:00
|
|
|
$ export OB_LIBDIR=/home/noel/tree/lib # The install location of libopenbabel.so
|
2008-05-24 18:18:27 +00:00
|
|
|
|
2009-03-23 02:13:53 +00:00
|
|
|
Next, compile the Java bindings:
|
|
|
|
|
$ cd $OB_JAVADIR
|
2009-09-21 11:12:00 +00:00
|
|
|
$ g++ -c -fpic openbabel_java.cpp -I../../include -I$JAVA_HOME/include -I$JAVA_HOME/include/linux
|
|
|
|
|
$ g++ -shared openbabel_java.o -L../../src/.libs -lopenbabel -o libopenbabel_java.so
|
2008-05-24 18:18:27 +00:00
|
|
|
|
2009-03-23 02:13:53 +00:00
|
|
|
Compile and run the test program:
|
|
|
|
|
$ export CLASSPATH=.:$OB_JAVADIR/openbabel.jar
|
2009-09-21 11:12:00 +00:00
|
|
|
$ $JAVA_HOME/bin/javac OBTest.java
|
2009-03-23 02:13:53 +00:00
|
|
|
$ export LD_LIBRARY_PATH=$OB_JAVADIR:$OB_LIBDIR
|
2009-09-21 11:12:00 +00:00
|
|
|
$ $JAVA_HOME/bin/java OBTest
|
2007-04-13 18:57:13 +00:00
|
|
|
|
2009-03-23 02:13:53 +00:00
|
|
|
If you get the output "Benzene has 0 atoms", you need to preload the OpenBabel library as follows:
|
2009-09-21 11:12:00 +00:00
|
|
|
$ LD_PRELOAD=$OB_LIBDIR/libopenbabel.so $JAVA_HOME/bin/java OBTest
|
2007-04-13 18:57:13 +00:00
|
|
|
|
2009-03-23 02:13:53 +00:00
|
|
|
*** Mac OS X Compilation
|
2007-04-13 18:57:13 +00:00
|
|
|
|
2009-09-21 11:12:00 +00:00
|
|
|
As for Linux, but use the following instructions to compile the bindings. Also, replace LD_LIBRARY_PATH with DYLD_LIBRARY_PATH.
|
|
|
|
|
|
2007-04-13 18:57:13 +00:00
|
|
|
% g++ -c -I/System/Library/Frameworks/JavaVM.framework/Headers \
|
|
|
|
|
openbabel_java.cpp
|
|
|
|
|
% g++ -dynamiclib -o libopenbabel.jnilib openbabel_java.o \
|
|
|
|
|
-framework JavaVM -L/usr/local/lib -lopenbabel
|