Ant Java task : how to get output to console and a file-always record build output without shell redirection
ant, java
Solution
Ant has a way to record output. http://ant.apache.org/manual/Tasks/recorder.html.
A recorder is a listener to the current build process that records the output to a file.
Several recorders can exist at the same time. Each recorder is associated with a file. The filename is used as a unique identifier for the recorders. The first call to the recorder task with an unused filename will create a recorder (using the parameters provided) and add it to the listeners of the build. All subsequent calls to the recorder task using this filename will modify that recorders state (recording or not) or other properties (like logging level).
It looks like meets your need.
<compile >
<record name="log.txt" action="start"/>
<javac ...
<record name="log.txt" action="stop"/>
<compile/>
Problem
I am using ant to start a Java program. I do not want to "loose" the output, after the program terminates. So I use the property '`output`' to store the output in a file. ``` <java classname="..." fork="true" output="....txt"> ``` Unfortunately I do not have any console output anymore. What would be a nice way to have the output on the console and in a txt file. I am looking for an alternative to ``` ant mytast > myFile.txt ``` because I do not want, that the "user" has to use shell redirection "> ..". . If he/she does not choose to redirect, the output is lost.