我从Java类中以编程方式启动Ant:
File buildFile= new File("buildAppl.xml");
if (!buildFile.exists()) {
return false;
}
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.setProperty("java.home", "C:\\Program Files\\Java\\jdk1.6.0_37");
p.addBuildListener(logger);
try {
p.fireBuildStarted();
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget("build");
p.fireBuildFinished(null);
} catch (BuildException e) {
p.fireBuildFinished(e);
return false;
}当我用Exclipse调试它时,我会得到以下错误:
X:\update\jTag\build\buildAppl.xml:114:执行这一行时发生了以下错误: X:\update\jTag\project\buildAppl.xml:107:无法使用SUN,因为它不可用。一个常见的解决方案是设置环境变量JAVA_HOME。
我检查了以下情况:
构建文件中rmic任务的描述类似于以下内容:
<rmic base="${classDirClient}" debug="true" classname="x.y.z.ProcessingServiceRmiImpl">
<classpath>
<fileset refid="classpathClient"/>
</classpath>
</rmic>
<rmic base="${classDirClient}" debug="true" classname="x.y.z.RmiXmlMessengerClient">
<classpath>
<fileset refid="classpathClient"/>
</classpath>
</rmic>在Eclipse中交互运行Ant时,它构建ok。
我能做些什么来避免这个错误呢?
发布于 2014-07-31 14:34:02
从Java5开始,不再需要rmic。Java 5及更高版本中的RMI系统可以使用动态代理(而不是静态预编译存根)操作,因此只有在必须支持Java1.4或更早版本的客户端时才需要rmic。
https://stackoverflow.com/questions/25059759
复制相似问题