0

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)

KMot
  • 467
  • 5
  • 13
  • Does this answer your question? [Generate JNI header files for class files in JDK 10](https://stackoverflow.com/questions/49506237/generate-jni-header-files-for-class-files-in-jdk-10) – ChrisMM Apr 08 '20 at 23:29
  • @ChrisMM, Not actually. I can create JNI header files using "javac -h" from command prompt, but I want to know if there is a way to use Eclipse to achieve this purpose. Apparently (from tutorials) this has been possible with "javah" before. – KMot Apr 09 '20 at 07:43
  • Combine with this post? https://stackoverflow.com/questions/9940381/how-to-generate-jni-header-file-in-eclipse – ChrisMM Apr 09 '20 at 12:24
  • Which version of Eclipse are you using? – Botje Apr 09 '20 at 13:32

2 Answers2

2

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.

Botje
  • 26,269
  • 3
  • 31
  • 41
  • 1
    I'm trying to apply this, but I keep getting `error: no source files` no matter which file I select. any ideas on that? – Piglet Apr 28 '21 at 05:26
0

try this:

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

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 20 '21 at 17:14
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30635245) – Shunya Dec 22 '21 at 15:18