我正在使用 ant 启动 Java 程序。
我不想在程序终止后“松散”输出。所以我使用属性“output”将输出存储在文件中。
<java classname="..." fork="true" output="....txt">
不幸的是,我没有任何控制台输出了。在控制台和 txt 文件中输出的好方法是什么。
我正在寻找替代品
ant mytast > myFile.txt
因为我不想,“用户”必须使用 shell 重定向“> ..”。 .如果他/她不选择重定向,则输出将丢失。
最佳答案
Ant 有一种记录输出的方法。 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).
看起来可以满足您的需求。
<compile >
<record name="log.txt" action="start"/>
<javac ...
<record name="log.txt" action="stop"/>
<compile/>
关于java - Ant Java 任务 : how to get output to console and a file-always record build output without shell redirection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10121929/