Skip to content
This repository was archived by the owner on Nov 8, 2026. It is now read-only.
elide-devPublic archive

About

Statically link JNI library with native-image

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

Important

Archived by Elide. Elide's fork of this project was retired on November 8, 2026 and is no longer maintained here. Its code, branches, and history remain available for reference. Upstream project: https://github.com/smasher164/staticjni.

Explore our current projects: myna, bemo, trufflecel, truffledata, and elide.

Statically-linked Native Image w/ JNI

Cross-platform build instructions.

  1. The header file HelloWorld.h was generated by running javac -h . HelloWorld.java. Since this is checked into the repo, it doesn't need to be run again.

    The dependency org.graalvm.nativeimage/svm has been added to the project. In this repo's case, the jar was unzipped into the classpath. If you're using a package manager or build system, follow their respective instructions to add a dependency.

  2. javac -cp . HelloWorld.java NativeFeature.java

  3. jar cfm HelloWorld.jar manifest.txt HelloWorld.class NativeFeature.class

    • Linux: cc -c -I "$JAVA_HOME/include" -I "$JAVA_HOME/include/linux" -o native.o Native.c
    • MacOS: cc -c -I "$JAVA_HOME/include" -I "$JAVA_HOME/include/darwin" -o native.o Native.c
    • Windows (msvc): cl /I "%JAVA_HOME%\include" /I "%JAVA_HOME%\include\win32" /c Native.c
    • Linux and MacOS: ar rcs libNative.a native.o
    • Windows (msvc): lib Native.obj
  4. native-image -jar HelloWorld.jar -H:CLibraryPath=.

About

Statically link JNI library with native-image

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages