If you have a Java project that uses JNI methods, you can generate a C++ JNI project from the Java project. The JNI project implements all the native interfaces in Java code.
To create a C++ JNI Library project:
The New JNI Library Library Project dialog opens.
The C++ JNI Library project is created with default implementations of all native functions.
The property java.library.path is added to the Java project's Run properties for the Java VM so that the new C++ library can be loaded using the call System.loadLibrary("name-of-your-CppJNILibrary").
The following IDE features are supported for the associated Java and native projects.
Feature | Description |
Navigating in the code editor from Java methods to their C/C++ implementation | Ctrl-click on the Java method and the code editor jumps to the C/C+ declaration or definition if it is found. |
Generating boilerplate code to call Java methods or access Java fields from the native side. |
Use the context menu to automatically generate code. Right-click a Java entity and choose Mixed
Development > Copy JNI Signature. The signature of the entity is copied
into your clipboard and you can paste it where appropriate.
The same works for boilerplate code to access (set or get) Java fields or call Java methods. Right-click on a Java field or method, then select Mixed Development > Copy call method code / Copy get field code / Copy set field code. The requested code is then copied into the clipboard. |
Regenerating JNI header files if interface in Java classes has been changed. |
Right-click on the Java class, then select Mixed Development > Generate JNI
header If a header file for that class exists in the open C++ projects, the IDE regenerates that existing header file. If a header file for that class doesn't exist in the open C++ projects, the IDE asks you to choose a directory for the new header file. The IDE generates both the header and '.cpp' files in the project. The C++ file contains empty implementations of all functions. |
Debugging both Java and C++ code at once. | If you run into a native method call while debugging Java code, you can step into it. The IDE will automatically attach the debugger and place a breakpoint in the beginning of the native method. |
Copyright © 2015, Oracle and/or its affiliates. All rights reserved.