javabuildant

Error while using Ant API for compilation of Java files - "error starting modern compiler"


I am programmatically using Ant to compile a set of Java files (using the javac task). On execution of the Java program, I get the error:

Error starting modern compiler

However, when I run the same build.xml from command-prompt instead of through the program, compilation takes place without any problesms.

Another question (http://stackoverflow.com/questions/2577790/error-starting-modern-compiler) seems to suggest that this error is caused when Ant tries to use a different version of javac from the one already loaded into the JVM. However, I am not specifying any particular compiler to be used, and the documentation (http://ant.apache.org/manual/index.html) seems to suggest that it should ideally used the javac loaded into the JVM.

The program works on some machines but fails on others, the only discernable difference between the machines being the environment variables. The program needs to be executed on several different machines, each having slightly varying environment variables. So changing these variables is not an acceptable solution.

I guess what I am looking for is some way to specify to Ant that for the javac task, use the compiler available in the JVM currently.


Solution

  • How exactly do you start ant from your java program ?
    Via Java api like

    File buildFile = new File("build.xml");
    Project p = new Project();
    ...
    

    via ant.bat / ant.sh ?
    from IDE like Eclipse ?

    Do you use JDK or JRE (the tools.jar is needed for javac) ?
    Do you use fork=true in the javac task ?
    Do you use the same user for ant via java and ant via commandline ?

    use :
    ant - diagnostics
    ant -debug
    ant -verbose

    <echoproperties prefix="ant"/>
    <echoproperties prefix="java"/>
    

    to get more details.