SWIG Java Examples

The following examples illustrate the use of SWIG with Java.

Running the examples

Please see the Windows page in the main manual for information on using the examples on Windows.

On Unix most of the examples work by making the Makefile before executing the program runme.java. The Makefile will output the swig generated JNI c code as well as the Java wrapper classes. Additionally the JNI c/c++ code is compiled into the shared object (dynamic link library) which is needed for dynamic linking to the native code. The Makefiles also compile the Java files using javac.

Ensure that the dynamic link library file is in the appropriate path before executing the Java program. For example in Unix, libexample.so must be in the LD_LIBRARY_PATH.

A Unix example:

$ make
$ export LD_LIBRARY_PATH=. #ksh 
$ java runme

Compatibility

The examples have been extensively tested on the following platforms: Your mileage may vary. If you experience a problem, please let us know by contacting us on the mailing lists.