Question

I want to build my code (which was written in the netbeans IDE) via ant. When I do this via the commandline I have no problems. But now I have to do it via Java. Therefore I use this code:

        File buildFile = new File("C:/Users/user1/Documents/project/trunk/src_java_fa2/RePestApplet/build.xml");
        Project p = new Project();
        p.setUserProperty("ant.file", buildFile.getAbsolutePath());
        p.init();
        ProjectHelper helper = ProjectHelper.getProjectHelper();
        p.addReference("ant.projectHelper", helper);
        helper.parse(p, buildFile);
        p.executeTarget(p.getDefaultTarget());

When I execute this I get this error:

Exception in thread "main" C:\Users\user1\Documents\project\trunk\src_java_fa2\RePestApplet\nbproject\build-impl.xml:894: The following error occurred while executing this line:
C:\Users\user1\Documents\project\trunk\src_java_fa2\RePestApplet\nbproject\build-impl.xml:1406: The following error occurred while executing this line:
C:\Users\user1\Documents\project\trunk\src_java_fa2\RePestStyle\nbproject\build-impl.xml:926: The following error occurred while executing this line:
C:\Users\user1\Documents\project\trunk\src_java_fa2\RePestStyle\nbproject\build-impl.xml:268: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\jmonkeyplatform\jdk\jre"

So it says that my JAVA_HOME variable is not set to the jdk. But when I check this I see:

set JAVA_HOME
>>> JAVA_HOME=C:\Program Files\jmonkeyplatform\jdk

Why would it think the JAVA_HOME variable is set to the jre ?

Was it helpful?

Solution

As the error message “com.sun.tools.javac.Main is not on the classpath” points out, the variable JAVA_HOME is just used because it didn’t find the compiler class com.sun.tools.javac.Main on the class path.

So it’s easier to include the tools.jar of your JDK in the class path, so ant will find the class com.sun.tools.javac.Main without depending on the environment variable.

OTHER TIPS

what is the content of the XML file?

a wild guess, does the XMl file have some paths that are assigned relatively i.e, /bin/xyz ... and not full path?

you may want to use full path inside the XML file , if any

Id add some debug output to your code -

p.getProperty("java.home");

To confirm what ant is using. If it is wrong then set it to

p.setProperty("java.home", "C:\\Program Files\\jmonkeyplatform\\jdk");

As to why this is occuring - Is your build file changing java.home?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top