Reputation: 5805
Java, JNI and C++: How do I generate a header file from native method declarations?
I have Java project, which communicates with C++ code through JNI. The challenge is now I need to add new methods. I first started by declaring the native methods in the java code. Now I need to regenerate the header file for the JNI methods. I work in Eclipse, not sure how to do this.
Upvotes: 2
Views: 9759
Reputation: 20812
This is not built into Eclipse but it is easy to do:
File » New... » XML File
to create an Ant file (code below) in your project.Project » Properties » Builders » New... » Ant Builder
to add the Ant file as a build step. Set Refresh to "project" so that generated files show up in the project. Be sure to put the build step after the Java Builder step because javah
reads compiled class
files.Now, you'll always have up-to-date header files whenever you change your Java code. You just have list the applicable classes in the Ant file.
<?xml version="1.0" encoding="UTF-8"?>
<project name="javah">
<mkdir dir="javah" />
<javah classpath="bin" destdir="javah">
<!-- list classes here -->
<class name="com.example.MyClass" />
</javah>
</project>
You can get a lot more sophisticated in the Ant script but the above is sufficient.
Upvotes: 3