This sample project shows how BridJ & JNAerator can be used to maintain a custom native library built on many platforms, along with its bindings.
To build on Unix (MacOS X, Linux, Solaris), simply type the following lines
git clone https://github.com/ochafik/nativelibs4java.git
cd nativelibs4java/libraries/BridJ/Examples/BasicExample
mvn clean install
This will automatically:
- Rebuild the native library for the host architecture (
libexample.soorlibexample.dylib) - Create the bindings under
target/generated-sources - Compile all the Java files under
src/main/java(you can put your own there, for instance to wrap C/C++ entities in Java ones) and create a JAR intarget - Run the tests in
src/test/java
You may want to:
- Add more
*.cppfiles undersrc/main/native/example: just add them insrc/main/native/example/Makefilewith aUNITS += mynewfileline, without the file extension. - Add more libraries under
src/main/native(each directory will need its ownMakefilethat can be copied from theexampleone) - Tweak the JNAerator config file
src/main/jnaerator/config.jnaerator(see JNAerator Wiki) - Port the build scripts and/or BridJ to a new architecture (platforms supported by dyncall should be extremely easy to port)
You may want to inspect pom.xml to update to a newer release of BridJ or JNAerator.