Creating a Java example

Java example using Eclipse

This page describes the procedure to build a Java example using the JNI interface included in the SDK, Core, and Linux Editions since Open NFC 4.3.0. The Java API of Open NFC is described in SIS_NFC_1003-188 document included in the release.

Source files

All files related to this procedure are located under the folder core/porting/jni. This folder contains:

Creating a new project

This section assumes that you are familiar with the client/server flavour of Open NFC — the JNI wrapper is only available in this flavour at the moment. If not, please try using first the win32_examples or Linux examples to learn how to start all components: Connection Center, Simulator or board, Open NFC Server, and finally client application.

We are also assuming that you have downloaded and unzipped the archive of the Open NFC SDK Edition (you could use as well the Core or Linux Edition), and that the files are available under /path/to/core/porting/jni.

We are giving these explanations for the Eclipse IDE, but of course it is perfectly possible to use a different development environment.

  1. Create a new project via “File” -> “New” -> “Java Project”
  2. Choose the name you want, we use “JNIExample” here.
  3. Click “Next >” then go to the “Libraries” tab.
  4. Click “Add External JARs…” and select the file /path/to/core/porting/jni/output/open_nfc.jar
  5. , then finally click “Finish”. The new project is created.

  6. Under “JNIExample” > “src” create a new Class, for example “JNIExampleClass”
  7. Create the code you want, importing org.opennfc.* classes. We assume here that you copy the contents of /path/to/core/porting/jni/example1/example/Example.java, just changing the class name. Of course, you can write any code you like here.
  8. Open the “(default package)” properties.
  9. In “Run/Debug Settings”, click “New…” then select “Java Application”.
  10. Choose the configuration name (“default_run”)
  11. In the “(x)= Arguments” tab, add the following line in the “VM arguments:” box. Please change the bold values with the appropriate values for your system. The opennfc.config option corresponds to the port your server is listening for clients on.

    -Xbootclasspath/p:open_nfc.jar -Dopennfc.config=1234 -Dsun.boot.library.path=. -Djava.library.path=/path/to/core/porting/jni/output/

Running the project

Now in order to run your project, you have to start the following components:

  1. Connection Center
  2. NFC Simulator (or start your NFC evaluation kit in the Connection Center)
  3. Server. Under Win32 environment, it can be found under /path/to/core/porting/win32/win32_examples/release/. Adapt the path for Linux or 64bits version. Start the server with (change nfcc_hal with nfcc_i2c if you have a kit):

    server_porting.exe cc:nfcc_hal 1234

Finally, you should be able to run your project from Eclipse, and see an output similar to this:

4.3
Virtual NFCC firmware 3.45a

Back to top

Except as noted otherwise, this content is licensed under the terms of the Apache 2.0 License. For details and restrictions, see the Content License.
Open NFC is a registered trademark of Inside Secure, All logos and graphics are copyrighted.