Bug 541

Summary: Ant build fails inside Eclipse with JDK 1.7u2
Product: [JogAmp] Jogl Reporter: Wade Walker <wwalker3>
Component: coreAssignee: Wade Walker <wwalker3>
Status: RESOLVED FIXED    
Severity: normal CC: sgothel
Priority: ---    
Version: 2   
Hardware: All   
OS: all   
Type: --- SCM Refs:
Workaround: ---

Description Wade Walker 2011-12-22 15:50:45 CET
There seems to be some incompatibility between JDK 1.7u2 and building inside Eclipse. It shows the following error building gluegen:

gluegen.build.c.impl:
       [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)

BUILD FAILED
C:\Users\wwalker\Documents\jogl2\gluegen\make\build.xml:409: The following error occurred while executing this line:
C:\Users\wwalker\Documents\jogl2\gluegen\make\build.xml:416: compilation failed

I'm investigating now -- it's probably some conflict between Oracle's new tools.jar and Eclipse. We've already seen when fixing the build for JDK 1.7 that javah behaves a bit differently now than it did in JDK 1.6.
Comment 1 Wade Walker 2011-12-22 16:51:50 CET
Can duplicate this on the command line:

> java -classpath "C:\Program Files\Java\jdk1.7.0_02\lib\tools.jar" com.sun.tools.javah.Main
-d "C:\Users\wwalker\Documents\jogl2\gluegen\build\gensrc\native"
-classpath "C:\Users\wwalker\Documents\jogl\gluegen\build\classes"
jogamp.common.os.MachineDescriptionRuntime

Exception in thread "main" java.lang.NullPointerException
        at com.sun.tools.javah.JavahTask.run(JavahTask.java:509)
        at com.sun.tools.javah.JavahTask.run(JavahTask.java:335)
        at com.sun.tools.javah.Main.main(Main.java:46)

Not sure why it fails like this, but works when run inside Ant on the command line. There may be something else on the classpath that's not being put there in the Eclipse run.
Comment 2 Wade Walker 2011-12-23 18:20:56 CET
Very strange. When I invoke javah like this, it fails:

jogl2\gluegen> java.exe -classpath "C:\Program Files\Java\jdk1.7.0_02\lib\tools.jar" com.sun.tools.javah.Main -d build\gensrc\native -classpath build\classes jogamp.common.os.MachineDescriptionRuntime

Doing it like this also fails (this is how ant -debug shows it being done inside Eclipse):

jogl2\gluegen> "C:\Program Files\Java\jre7\bin\java.exe" -classpath "C:\Program Files\Java\jdk1.7.0_02\lib\tools.jar" com.sun.tools.javah.Main -d build\gensrc\native -classpath build\classes jogamp.common.os.MachineDescriptionRuntime

But like this, it succeeds:

jogl2\gluegen> "C:\Program Files\Java\jdk1.7.0_02\bin\java.exe" -classpath "C:\Program Files\Java\jdk1.7.0_02\lib\tools.jar" com.sun.tools.javah.Main -d build\gensrc\native -classpath build\classes jogamp.common.os.MachineDescriptionRuntime

Continuing to investigate. The two java executables appear identical, so there must be some path dependency perhaps.
Comment 3 Wade Walker 2011-12-24 01:45:12 CET
Found the problem. In Java 7, Ant needs to be launched with a Java executable from a JDK, not a JRE, or else the javah task won't work correctly, even if you set the Ant java.home property to the JDK directory.

Eclipse launches Ant with the workbench VM, which is not set from JAVA_HOME, so it ends up chosing C:\Program Files\Java\jre7\bin\javaw.exe instead of C:\Program Files\Java\jdk1.7.0_02\jre\bin\javaw.exe, which makes it unable to use tools.jar correctly (since it's only present in the JDK).

I changed the wiki at http://jogamp.org/wiki/index.php/Building_JOGL_in_Eclipse to give instructions on how to tell Eclipse to launch Ant with your JAVA_HOME JDK instead of the other JRE.