开发者

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 wi开发者_如何学运维thout 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.


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.


On your erring machines, make sure the Eclipse Java VM is pointing to the same location specified in JAVA_HOME. From eons ago I remember that there was something else you could do with tools.jar within Eclipse itself to get rid of this problem. I will update my answer when the old cheese starts working again.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜