KMot
KMot

Reputation: 507

how to use javac instead of javah for creating c++ JNI header using Eclipse

I am trying to follow a tutorial (http://www.lithiumhead.com/notes/windows_jni) to generate the c++ header file from Eclipse. It is based on using javah (like many other tutorials I have found), but javah does not exist in newer versions of jdk. Simply replacing javah by javac does not work as I get "error: invalid flag: -jni". I know I have to use -h flag, but I do not know where! Here is a snapshot of the current state:

enter image description here

I would appreciate your help, as well as a link to a good (step-by-step) tutorial that is up-to-date (works with newer versions of jdk, eclipse, etc)

Upvotes: 0

Views: 4530

Answers (2)

user17725577
user17725577

Reputation: 1

try this:

-h jni -d ${env_var:TMPDIR} -s ${selected_resource_loc}

Upvotes: 0

Botje
Botje

Reputation: 30937

You almost got it, you simply need to change the flags a bit. The full line is

-h jni -d ${env_var:TMPDIR} ${selected_resource_loc}

broken into parts:

  • -h jni: output headers in the jni directory, relative to the working directory. (which I set to the project itself, not bin)
  • -d ${env_var:TMPDIR}: Output class files into a temporary directory. We do not care about it, so I made it output to $TMPDIR. On Windows you probably want TEMP instead.
  • ${selected_resource_loc}: Pass the full path to the currently selected file. You can also hardcode "HelloWorld.java" instead.

Running the tool generated a jni/helloJNI_HelloJNI.h for me.

Here's a screenshot of my window, for reference. window.

Upvotes: 2

Related Questions