2

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?

sers
  • 3,139
  • 3
  • 20
  • 28
  • "What can I do to circumvent this error?" - don't use rmic! It isn't needed for Java 6, RMI can work perfectly well without the stubs that `rmic` generates unless you have clients running Java 1.4 or earlier (and then you have other problems...). – Ian Roberts Jul 31 '14 at 13:33
  • Thanks @Ian for the hint. I removed the rmic tasks from the build file (support for Java 1.4 is not needed) and compile runs through now. (I cannot post this as an answer for lack of reputation. well ...) – sers Jul 31 '14 at 14:22

1 Answers1

0

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 need rmic if you have to support clients on Java 1.4 or earlier.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183