Java Native Access

Java Native Access (JNA) is a Java program library for accessing platform-specific ( "native" ) dynamic libraries (DLLs in Windows or " shared libraries " on other systems). This needs to be no platform- specific code written in contrast to JNI.

JNA is comparable in function to the Platform Invocation Services ( P / Invoke). NET on Windows. It supports automatic conversion between some C and Java data types. The minimum required Java version is 1.4.

License

LGPL version 2.1 or higher and (V4.0 ) The Apache Software License V2.0.

Applications

The following software projects use JNA:

  • JRuby
  • Java Media Framework # FMJ
  • IntelliJ IDEA

Example

The following example loads the standard C library to call the printf function. This example works on Microsoft Windows and Linux / Unix / Mac OS X.

Import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.Platform;   / ** Simple example of a declaration and use of a dynamic program library or "shared library". * / public class HelloWorld {    public interface CLibrary extends Library {      CLibrary INSTANCE = ( CLibrary )     ? Native.loadLibrary ( ( Platform.isWindows () " msvcrt ", " c" ),          CLibrary.class );        void printf (String format, Object ... args);    }      public static void main ( String [ ] args ) {      CLibrary.INSTANCE.printf ( "Hello, World \ n");      for (int i = 0; i < args.length; i ) {        CLibrary.INSTANCE.printf ( " argument% d:% s \ n", i, args [i ]);      }    } } Web Links

  • Java Native Access Homepage (English )
  • Java Native Access - Download page ( English )
  • Java Native Access - Users Mailing List ( English )

References

  • Java library
432220
de