ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Toomey, Kevin H (ATS, IT)" <>
Subject RE: Redirecting <javac> compile errors
Date Wed, 16 Jan 2008 15:30:21 GMT
Using the command line or sending System.err to logger both work as expected (javac errors
logged to the log file). The issue is that this is for an application which among things,
manages several builds simultaneously, so getting the correct output to the correct log becomes
problematic with those approaches. 

Further digging after my original post showed that as expected, this question has been raised
before, and is due to how the JDK is architected as opposed to Ant's functionality. It looks
like support for JSR199 (java compiler API) would give me what I'm looking for, but I couldn't
tell for sure if/when that support would be available with Ant. For now, I'm working around
this by changing the common.xml to create a new process and pipe it's output to the correct
file. It's not exactly what I want, but it'll be fine for now.


-----Original Message-----
From: James Abley []
Sent: Tuesday, January 15, 2008 5:06 PM
To: Ant Users List
Subject: Re: Redirecting <javac> compile errors

On 10/01/2008, Toomey, Kevin H (ATS, IT) <> wrote:
> Hi,
> I'm using a Java class to execute an Ant project, and am unable to direct compile errors
to the log file used by my BuildLogger.
> Here's an abbreviated version of my code:
> Project p = new Project();
> p.init();
> p.setUserProperty("ant.file", "common.xml") //more on this later
> DefaultLogger logger = new DefaultLogger();
> p.addBuildListener(logger);
> PrintStream ps = new PrintStream(new FileOutputStream("task.log"));
> logger.setOutputPrintStream(ps);
> logger.setErrorPrintStream(ps);
> p.executeTarget("myTarget");
> As for the common.xml file above, it does some build pre-processing tasks including getting
the files I want to build from the source repository. Among those files is the "build.xml"
file that contains the <javac> task.
> common.xml triggers "build.xml" using an <ant targetFile="build.xml"....../>
> All works well when I run my Java class from a command prompt, unless there is a compile
error during the <javac> task. While my Java class gets notified of the error via a
BuildException, the compiler error messages get dumped to my command line window (Windows)
instead of "task.log".
> I understand that the Sun Javac class (I'm using the modern compiler in Ant 1.7) defaults
to System.err, but is there any way I can force it to my output file?
> Thanks,
> Kevin

What happens when you run your build using the ANT command line?

Have you tried replacing System.err with a reference to your logger?



To unsubscribe, e-mail:
For additional commands, e-mail:

This communication, including attachments, is
for the exclusive use of addressee and may contain proprietary,
confidential and/or privileged information.  If you are not the intended
recipient, any use, copying, disclosure, dissemination or distribution is
strictly prohibited.  If you are not the intended recipient, please notify
the sender immediately by return e-mail, delete this communication and
destroy all copies.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message