You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Ken Wood <kw...@i2.com> on 2000/11/30 20:37:32 UTC

Seeking understanding of how Javac task works.

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("sun.tools.javac.Main");
            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", location);
        }
        catch (Exception ex) {
            if (ex instanceof BuildException) {
                throw (BuildException) ex;
            } else {
                throw new BuildException("Error starting classic compiler: ", ex, location);
            }
        }

Re: Seeking understanding of how Javac task works.

Posted by Peter Donald <do...@apache.org>.
At 04:03  30/11/00 -0600, you wrote:
>That was my problem. I was focused on
>the lines of code, and the "//" delimiters,
>that I didn't even SEE the */...
>
>Duh!
>
>No IDE, just plain emacs, not even configured to java
>mode.

You should get jde - it makes things a *lot* easier ;)

Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*


Re: Seeking understanding of how Javac task works.

Posted by Ken Wood <kw...@i2.com>.
That was my problem. I was focused on
the lines of code, and the "//" delimiters,
that I didn't even SEE the */...

Duh!

No IDE, just plain emacs, not even configured to java
mode.

Ah, well, I said it would be "mbarassingly obvious"
and I was right :^)


Nico Seessle wrote:
> 
> ----- Original Message -----
> From: "Ken Wood" <kw...@i2.com>
> To: <an...@jakarta.apache.org>
> Sent: Thursday, November 30, 2000 8:37 PM
> Subject: Seeking understanding of how Javac task works.
> 
> > 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:
> >
> 
> In my version of javac (may be old, but I don't think that part changed)
> this first statement is commented out...
> 
> > 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....
> >         */
> 
> ... and you even included the end of the comment in you mail :-)
> 
> No IDE with Syntax-Highlighting available ? ;-)
> 
> Nico

Re: Seeking understanding of how Javac task works.

Posted by Nico Seessle <Ni...@epost.de>.
----- Original Message -----
From: "Ken Wood" <kw...@i2.com>
To: <an...@jakarta.apache.org>
Sent: Thursday, November 30, 2000 8:37 PM
Subject: Seeking understanding of how Javac task works.


> 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:
>

In my version of javac (may be old, but I don't think that part changed)
this first statement is commented out...

> 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....
>         */

... and you even included the end of the comment in you mail :-)

No IDE with Syntax-Highlighting available ? ;-)

Nico