• Stars
    star
    156
  • Rank 232,615 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 14 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A JNI code generator based on the JNI generator used by the eclipse SWT 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

More Repositories

1

mqtt-client

A Java MQTT Client
Java
1,260
star
2

jansi

Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.
Java
1,034
star
3

leveldbjni

A Java Native Interface to LevelDB
Shell
532
star
4

hawtdispatch

The libdispatch style API for Java and Scala
Java
184
star
5

rocksdbjni

A Java JNI driver to rocksdb
Shell
61
star
6

hawtjournal

A variable length record, checksumming, append only rotating log implementation with graceful recovery
Java
55
star
7

stompjms

The JMS interface to STOMP
Java
46
star
8

fuse-extra

Fuse Extra: A collection of addons and plugins for the open source projects FuseSource support'
Java
34
star
9

coffeebar

The CoffeScript based Web Framework for Rapid Application Development.
JavaScript
31
star
10

jansi-native

Builds the JNI libraries for the jansi project
Java
31
star
11

coffeejade

CoffeeScript version of Jade
JavaScript
24
star
12

sap-quickstarts

Java
11
star
13

jmspool

JMS Connection Pool
Java
10
star
14

hudsongen

Generates FuseSource hudson configuration using Scalate
Scala
8
star
15

rrd4j

RRD4J is a high performance data logging and graphing system for time series data
Java
7
star
16

jdbm

Git mirror of the JDBM2 project
Java
6
star
17

jvmassert

Integrates Scala assertions with the JVM assertion framework
Scala
6
star
18

hawtjms

Multi-Protocol JMS v1.1 client
Java
5
star
19

fusemq-c

C client to FuseMQ and ActiveMQ
C++
4
star
20

fuse-console

A web console for Fuse
JavaScript
3
star
21

fabric

Old repo for Fuse Fabric: its now moved to https://github.com/fusesource/fuse
Java
3
star
22

joram-jms-tests

A mavenized distribution of the Joram JMS tests
Java
2
star
23

build-scripts

A collection of handy scripts for developing code with maven, git, java etc
Ruby
2
star
24

crowdmysql

MySQL based user store for Crowd
Java
2
star
25

hudson-results

Java
2
star
26

fuse-rhq-bundles

RHQ bundles for JBoss Fuse
1
star
27

sap-certification-tests

Java
1
star