ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ken Wood <>
Subject Seeking understanding of how Javac task works.
Date Thu, 30 Nov 2000 19:37:32 GMT
After months of using ant, I'm trying to learn more
about how it works.

In the doClassicCompile part of Javac I see the
code shown below. To me, it seems like the copiler
is called TWICE, so I'm trying to understand what is
going on. I'm sure once someone explains this, it
will be embarassingly obvious. Meantime....

My comments show where I'm confused:

Comment: Here is first invocation of compiler.
        if (!compiler.compile(cmd.getArguments())) {
            throw new BuildException("Compile failed");

Comment: So, it failed, so we go into a try block and try the compiler again....
        try {
            // Create an instance of the compiler, redirecting output to
            // the project log
            OutputStream logstr = new LogOutputStream(this, Project.MSG_WARN);
            Class c = Class.forName("");
            Constructor cons = c.getConstructor(new Class[] { OutputStream.class, String.class
            Object compiler = cons.newInstance(new Object[] { logstr, "javac" });

Comment: Here is where we compile again.

            // Call the compile() method
            Method compile = c.getMethod("compile", new Class [] { String[].class });

            Boolean ok = (Boolean)compile.invoke(compiler, new Object[] {cmd.getArguments()});
            if (!ok.booleanValue()) {
                throw new BuildException(FAIL_MSG, location);
        catch (ClassNotFoundException ex) {
            throw new BuildException("Cannot use classic compiler, as it is not available",
        catch (Exception ex) {
            if (ex instanceof BuildException) {
                throw (BuildException) ex;
            } else {
                throw new BuildException("Error starting classic compiler: ", ex, location);

View raw message