3

I am trying to use the javah task in an ant build file in Eclipse and I keep getting the following error:

BUILD FAILED

C:\sandbox\build-jni.xml:7: Can't load javah

Here is my build-jni.xml file:

<project>
<property name="bin" location="bin" />


<target name="generate-jni">
    <javah destdir="${bin}" classpath="${bin}">

        <class name="org.example.ExecJNI" />
    </javah>
</target>

Any thoughts as to why I'm getting that error? My project is pointing to the JDK and not the JRE

  • I tested this on Indigo Service Release 1 Build id: 20110916-0149 and java version "1.7.0_15" and it works fine. – Java42 Feb 23 '13 at 04:09
  • Thanks, @ChuckFricano! Seems I moved past that BUILD FAILED error, but now I get the following: `generate-jni: [javah] Exception in thread "main" java.lang.NullPointerException [javah] at com.sun.tools.javah.JavahTask.run(JavahTask.java:509) [javah] at com.sun.tools.javah.JavahTask.run(JavahTask.java:335) [javah] at com.sun.tools.javah.Main.main(Main.java:46)` – Jason Jacob Feb 24 '13 at 16:06
  • Additionally, I do have C:\Program Files\Java\jdk1.7.0_15\tools.jar in my Ant Home Entries in Window --> Preferences. Also, I'm using Eclipse Version: Indigo Service Release 2 Build id: 20120216-1857 – Jason Jacob Feb 24 '13 at 16:08
  • Answer the original question yourself in the "Your Answer" area with what you found to be the problem/solution and open a new question for the new symptom. – Java42 Feb 24 '13 at 16:19
  • I upvoted this question because I was getting a 'can't load javah' error in a different application but your question helped me figure out how to solve the can't load javah problem - it was an openjdk-6-jdk ANT 1.8.3 dependency – Jeremy Hajek Aug 30 '13 at 04:49

1 Answers1

3

Turned out I didn't have C:\Program Files\Java\jdk1.7.0_15\tools.jar in my Ant Home Entries in Window --> Preferences. That seemed to fix the problem.

  • After adding tools.jar to the ant runtime classpath, I also experienced (Eclipse Kepler for Windows 7 64-bit) the javah null pointer exception mentioned above. The correct fix for this subsequent problem was to specify "Run in Same JRE as workspace" on the JRE tab of each ant build file in the Run -> External Tools -> External Tools Configurations dialog. If you have multiple JREs installed, you might have to specify a specific (i.e., separate) JRE from the list of installed JREs. – Scott Dec 22 '13 at 22:43
  • Alternately, you can access the JRE tab in the "Edit Configuration dialog" via a right-click on the build file (in Project Explorer) -> Properties -> Run/Debug Settings; click on the build file, then press the Edit button. – Scott Dec 23 '13 at 23:59
  • If you have multiple JREs installed, you can still use "Run in Same JRE as workspace" (see first comment above) if you also supply a specific JVM in the eclipse.ini file with the -vm option. This might be the best solution because it guarantees which JVM Eclipse will run under. – Scott Dec 31 '13 at 01:49