How to make javac compiler write the output to both file and console?

一世执手 提交于 2019-12-22 05:38:31

问题


I am running javac task using ant and I send the output to a log file using -Xstdout compiler argument for reporting purposes, but I would like the output also still being send to the console so hudson can capture it for on screen review.

Is there a way for this to be done?


回答1:


Just came across another alternative using the recorder task. Nearer as you don't have to introduce new targets.

<compile >
    <record name="log.txt" action="start"/>
    <javac ...
    <record name="log.txt" action="stop"/>
<compile/>



回答2:


use the ant task with an output attribute to call a target that has the javac task.

e.g.

<target name="javac" depends="libs" description="Compile java source">
    <mkdir dir="${classes.dir}" />
    <ant target="actual-javac" output="javac.log"/>
</target>

<target name="actual-javac">
    <javac .../>
    </javac>
</target>



回答3:


you can use tee on any process on the command line to output to the console and a file:

>myprocess.sh | tee myprocess.log

will print the output of myprocess.sh both to the console and myprocess.log.



来源:https://stackoverflow.com/questions/1235970/how-to-make-javac-compiler-write-the-output-to-both-file-and-console

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!