HawtJNI Example

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

License

License

GroupId

GroupId

org.fusesource.hawtjni
ArtifactId

ArtifactId

hawtjni-example
Last Version

Last Version

1.18
Release Date

Release Date

Type

Type

jar
Description

Description

HawtJNI Example
A JNI code generator based on the JNI generator used by the eclipse SWT project
Project Organization

Project Organization

FuseSource, Corp.
Source Code Management

Source Code Management

https://github.com/fusesource/hawtjni/tree/hawtjni-project-1.18/hawtjni-example

Download hawtjni-example

How to add to project

<!-- https://jarcasting.com/artifacts/org.fusesource.hawtjni/hawtjni-example/ -->
<dependency>
    <groupId>org.fusesource.hawtjni</groupId>
    <artifactId>hawtjni-example</artifactId>
    <version>1.18</version>
</dependency>
// https://jarcasting.com/artifacts/org.fusesource.hawtjni/hawtjni-example/
implementation 'org.fusesource.hawtjni:hawtjni-example:1.18'
// https://jarcasting.com/artifacts/org.fusesource.hawtjni/hawtjni-example/
implementation ("org.fusesource.hawtjni:hawtjni-example:1.18")
'org.fusesource.hawtjni:hawtjni-example:jar:1.18'
<dependency org="org.fusesource.hawtjni" name="hawtjni-example" rev="1.18">
  <artifact name="hawtjni-example" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.fusesource.hawtjni', module='hawtjni-example', version='1.18')
)
libraryDependencies += "org.fusesource.hawtjni" % "hawtjni-example" % "1.18"
[org.fusesource.hawtjni/hawtjni-example "1.18"]

Dependencies

test (2)

Group / Artifact Type Version
junit : junit jar 4.13.1
log4j : log4j jar 1.2.17

Project Modules

There are no modules declared in this project.

HawtJNI

Description

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

Features

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

Synopsis

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 @JniClass. The following example will expose the C open function as a java method:

@JniClass
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 System.loadLibrary method:

@JniClass
public class Platform {
    static {
        System.loadLibrary("hawtjni-example");
    }
    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 Library helper class that HawtJNI provides:

@JniClass
public class Platform {
    private static Library library = new Library("hawtjni-example", 1, 0, 0);
  	static {
  	    library.load();
  	}
    public static native long open (String file, int flags, int mode);
}

To generate the JNI code, first compile your annotated class, then use the hawtjni-generate.jar 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 target/classes directory. The generated JNI classes will be placed in the target/native directory.

More Docs:

http://fusesource.github.io/hawtjni/documentation/developer-guide.html

org.fusesource.hawtjni

FuseSource

Versions

Version
1.18
1.17
1.16
1.15
1.14
1.13
1.12
1.11
1.10
1.9
1.8
1.7
1.6
1.5
1.4
1.3
1.2
1.1
1.0