الأربعاء، ١٧ أغسطس ٢٠١١

Java Native Access


Java Native Access

Java Native Access provides Java programs easy access to native shared libraries without using the Java Native Interface. JNA's design aims to provide native access in a natural way with a minimum of effort


JNA Development First Steps

Here are a few things you have to take care of when starting a JNA project

Download jna.jar from the JNA project site (http://java.net/projects/jna/downloads) and add it to your project's build path. This file is the only JNA resource you need.    Remember that jna.jar must also be included in the run-time classpath

    Find the names of the DLLs that your Java code will access. The DLL names are required to initialize JNA's linkage mechanisms    

 Create Java interfaces to represent the DLLs your application will access 

 Test linkage of your Java code to the native functions. The first example below, "Linkage: What's in a Name?", describes the exceptions to expect when JNA can't find a DLL or a function in a DLL


Figure 1. Creation of a Java proxy object for a DLL


From last figure we noticed that JNA work with Proxy pattern, it’s like RMI proxy
 
Now from this small introduction, lets start JNA test  GOoO

First, let's write the Native (CPP) library using MS Visual Studio 2008 see this figure


 Now we have the file " JNA_TEST.dll" >> copy this file to System32 under windows directory = till now every thing is good
                    
     Let's write the Java program that will call this native function, I will use netbeanse IDE 7.0
   First I will write JNA interface then Main class see this figure








References:
http://en.wikipedia.org/wiki/Java_Native_Access

هناك تعليق واحد: