I start Ant programmatically from within a Java class:
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;
}
When I debug it with Exclipse I get the following error:
X:\update\jTag\build\buildAppl.xml:114: The following error occurred while executing this line: X:\update\jTag\project\buildAppl.xml:107: Cannot use SUN rmic, as it is not available. A common solution is to set the environment variable JAVA_HOME
I have checked the following:
- Environment variables JAVA_HOME and PATH are set correctly.
- The eclipse preference "Installed JREs" defaults to C:\Program Files\Java\jdk1.6.0_37
- The project property "java.home" is set to "C:\Program Files\Java\jdk1.6.0_37" (see above)
The description of the rmic task in the build file looks similar to this:
<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>
When running Ant interactively in Eclipse it builds ok.
What can I do to circumvent this error?
As of Java 5,
rmic
is no longer required. The RMI system in Java 5 and later can operate using dynamic proxies rather than statically pre-compiled stubs, so you only needrmic
if you have to support clients on Java 1.4 or earlier.