Need help with hawtjni?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

131 Stars 56 Forks Apache License 2.0 291 Commits 18 Opened issues


A JNI code generator based on the JNI generator used by the eclipse SWT project

Services available


Need anything else?

Contributors list



HawtJNI is a code generator that produces the JNI code needed to implement java native methods. It is based on the jnigen code generator that is part of the SWT Tools project which is used to generate all the JNI code which powers the eclipse platform.

Maven Central


  • jni code generated from annotations on your java code
  • maven integration


There are many open source JNI code generators available, but if you're performance sensitive, the code generator used by the eclipse SWT project is by far the best option. The biggest problem is that it was not developed to be reused by other projects. It was tightly coupled to producing the SWT jni libraries and it could only be run within the eclipse platform.

HawtJNI takes that code generator and makes it more generally accessible to any project.

Example Usage

Your JNI methods must be defined as static native methods in a class annotated with

. The following example will expose the C
function as a java method:
public class Platform {
    public static native long open (String file, int flags, int mode);

You will also need to tell the JVM to load the native library when your class is loaded. You can do this using the standard

public class Platform {
    static {
    public static native long open (String file, int flags, int mode);

If you want to bundle the native library in as a resource of your jar, so that it can be automatically unpacked if it cannot be be found in your java library path. Then a better option is to use the

helper class that HawtJNI provides:
public class Platform {
    private static Library library = new Library("hawtjni-example", 1, 0, 0);
    static {
    public static native long open (String file, int flags, int mode);

To generate the JNI code, first compile your annotated class, then use the

runnable jar as follows:
java -jar hawtjni-generate.jar -o target/native target/classes

The above example expects your compiled java classes to be in the

directory. The generated JNI classes will be placed in the

More Docs:

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.