Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create jni header file with IntelliJ IDEA

I want to create the head file in IntelliJ IDEA. This is the way I do it:

file>setting>Tools>External Tools

then I click +, specify the title and set the parameters as follow:

Program: C:\Program Files\Java\jdk1.8.0_25\bin

Parameters: -d C:\Users\Administrator\Documents\Visual Studio 2013\Projects\JniExampleLibrary -jni Example.JniExample

Working Directory: C:\Program Files\Java\jdk1.8.0_25\bin

but after clicking ok, there is no JniExample.h file in the path defined above with -d

Would you please tell me what is the problem with it?

Thanks in advance

like image 876
Sona Avatar asked Sep 15 '15 06:09

Sona


People also ask

Where is JNI H located?

/usr/lib/jvm/java-6-openjdk-amd64/include/jni. h /usr/lib/jvm/jdk1. 7.

What is JNI used for?

JNI is the Java Native Interface. It defines a way for the bytecode that Android compiles from managed code (written in the Java or Kotlin programming languages) to interact with native code (written in C/C++).

Can I use IntelliJ idea for Java?

While IntelliJ IDEA is an IDE for Java, it also understands and provides intelligent coding assistance for a large variety of other languages such as SQL, JPQL, HTML, JavaScript, etc., even if the language expression is injected into a String literal in your Java code.


2 Answers

Here are the IntelliJ IDEA settings I use to generate the .h file: (This applies to IDEA version 12.1.6, probably similar in other versions)

  1. File->Settings->External Tools
  2. Click the + button for the "Edit Tool" dialog
  3. The following are the form name/value pairs I used:
    • Name: javah
    • Group: Java
    • Description: Java Native Interface C Header and Stub File Generator
    • Options: Check All
    • Show in: Check All
    • Tool Settings...
    • Program: $JDKPath$\bin\javah.exe
    • Parameters: -jni -v -d $FileDir$ $FileClass$
    • Working directory: $SourcepathEntry$
  4. Click OK, Click OK
  5. Navigate to your java class with the native method
  6. With the java class being shown in the editor, go to Tools->Java->javah
  7. Notice the .h file that was generated in the same directory as your class.
like image 126
kastmaster Avatar answered Sep 22 '22 16:09

kastmaster


I am using Java 11 (OpenJDK) to compile, so I do not have javah available.

Since now the option to create header files is included in javac, I added it as an compiler option.

  1. File->Settings->Build, Execution, Deployment->Compiler->Java Compiler
  2. In "Additional command line parameters" add: -h YourOutDir

(IntelliJ Community 2019.2, other versions should be similar)

Example:

-h C:/Development/Java/YourApp/cpp

I did not have any luck with "-h $FileDir$" or other macro commands of IntelliJ.

like image 23
Gunnar Bernstein Avatar answered Sep 22 '22 16:09

Gunnar Bernstein