Skip to content
Olivier Chafik edited this page Nov 8, 2022 · 3 revisions

How to build BridJ

BridJ is built as part of the NativeLibs4Java sub-projects.

Full build (first time)

This will build all of NativeLibs4Java's projects, including JNAerator. It will take some time, so you'll want to have a coffee during the build (if you've never used Maven before, this can take up to 15 minutes, so that might be enough for two coffees).

Subsequent builds will be much quicker (see next section), and can be launched from your Maven-aware IDE of choice.

  • First, install some basic build dependencies:
# On Debian Bullseye:
sudo apt-get install maven mercurial gcc g++ cmake make openjdk-17-jdk
  • Checkout the sources:
git clone https://github.com/nativelibs4java/BridJ
cd BridJ
  • Run the following Maven command :
mvn clean install

# Some tests might fail: let us know which ones / on which platform!
# To ignore the failures, try again with:
mvn clean install -DskipTests

BridJ's JARs are in Runtime/Bridj/target (pick bridj-x.x-SNAPSHOT.jar if you don't have specific size needs).

JAR File C C++ COM MFC Objective-C .NET Windows MacOS X Linux Solaris FreeBSD
bridj-x.x-SNAPSHOT.jar x x x x x x x x x x
bridj-x.x-SNAPSHOT-c-only.jar x x x x x
bridj-x.x-SNAPSHOT-windows-only.jar x x x x x x
bridj-x.x-SNAPSHOT-unix-only.jar x x x x x x
bridj-x.x-SNAPSHOT-macosx-only.jar x x x x

Porting to a new platform

TODO(ochafik): update this section w/ Docker / GitHub actions instructions.

See README.md at the root of the repo.

When building on a platform not supported by BridJ, you must update getEmbeddedLibraryPaths in Platform.java so it can find your binary at runtime (also check JNI.java for good measure).

About BridJ's source code

BridJ contains Java and C code.

Some of its sources are autogenerated from Velocity templates. For instance, all the Pointer.getInt, .setInt, getFloat, .setFloat... are generated automatically from a template.

So if you look for Pointer.java and JNI.java, they're not directly in the source control : they're created during the Maven build from their template located in src/main/velocity.

Likewise, some test classes are autogenerated, which helps cover more cases with less code (there's even autogenerated C functions in the test library, that is matched by the corresponding autogenerated test cases on the Java side).

Clone this wiki locally