原因很长而且很无聊,但是我需要运行一个 Ant 脚本来从 Java 1.4 应用程序编译 Java 1.5 代码。不过,我不断收到此错误:
BUILD FAILED
build.xml:16: 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:\j2sdk1.4.2_16\jre"
在我的代码中,我有:
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.setProperty("java.home", "C:\Program Files\Java\jdk1.6.0_04");
p.fireBuildStarted();
p.init();
// so on and so forth
但它忽略了它。我也尝试过 p.setUserProperty(String, String),但这也不起作用。有没有办法在不启动单独进程的情况下做到这一点?