For now, I'm just creating a simple program using JNI to mess around with and learn. I figured using Ant for building would make it a lot easier. Here is my project structure:
src/pkg/Test.java
bin/pkg/Test.class
c/
build.xml
Test.java:
package pkg;
public class Test {
public static void main(String[] args) {
System.out.println(new Test().getInt());
}
public native int getInt();
}
build.xml:
<project name="Test" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="bin.dir" value="bin"/>
<target name="clean">
<delete dir="${bin.dir}"/>
</target>
<target name="compile" depends="clean">
<mkdir dir="${bin.dir}"/>
<javac srcdir="${src.dir}" destdir="${bin.dir}" includeantruntime="false"/>
</target>
<target name="build-c" depends="compile">
<javah outputFile="test.h" classpath="${bin.dir}" class="pkg.Test"/>
</target>
<target name="main" depends="build-c"/>
</project>
Exception:
build-c:
[javah] Exception in thread "main" java.lang.NullPointerException
[javah] at com.sun.tools.javah.JavahTask.run(JavahTask.java:503)
[javah] at com.sun.tools.javah.JavahTask.run(JavahTask.java:329)
[javah] at com.sun.tools.javah.Main.main(Main.java:46)
I tried looking up the exception online and there were 2 posts I saw about it (javah NullPointerException while using ANT in Eclipse Indigo & "Can't load javah" error in Eclipse). I followed both of the advice in those posts. I ensured the default JRE was a JDK (jdk1.8.0_111), added tools.jar to the Ant Home Entries, and changed the build.xml Run/Debug Settings to run in the same JRE as the workspace. None of these things helped unfortunately. Any help would be greatly appreciated, and if there is any other info you need just let me know.