Apache Ant - 带有“[java]”标签的程序输出

时间:2015-04-25 01:52:32

标签: java ant

一个愚蠢的问题,但我无法在任何地方找到答案。

目前正在学习Apache Ant,我开始创建一个非常基本的构建文件和java项目,它将一行字符串输出到控制台。这是我使用命令

时输出的内容

ant compile jar run

PS C:\Users\zayd\Desktop\Apps\pbox> ant compile jar run
Buildfile: C:\Users\zayd\Desktop\Apps\pbox\build.xml

compile:
    [mkdir] Created dir: C:\Users\zayd\Desktop\Apps\pbox\build\classes
    [javac] C:\Users\zayd\Desktop\Apps\pbox\build.xml:9: warning: 'includeantruntime' was not set, defaulting to build.s
ysclasspath=last; set to false for repeatable builds
    [javac] Compiling 8 source files to C:\Users\zayd\Desktop\Apps\pbox\build\classes

jar:
    [mkdir] Created dir: C:\Users\zayd\Desktop\Apps\pbox\build\jar
    [jar] Building jar: C:\Users\zayd\Desktop\Apps\pbox\build\jar\Main.jar

run:
    [java] ~We'll go down in history~

BUILD SUCCESSFUL
Total time: 1 second

有没有办法删除与程序输出一起打印的'[java]'标签?

2 个答案:

答案 0 :(得分:2)

默认情况下,不,你不能。输出中的任务前缀由Ant的日志记录机制控制,而不是由java任务本身控制,因此无法更改java任务用法以删除此输出。

唯一的方法是编写自己的BuildLogger来自定义构建事件消息,然后指示Ant使用此自定义记录器,而不是默认情况下Ant使用的DefaultLogger。请参阅https://ant.apache.org/manual/listeners.html(该链接包含指向编写自己的侦听器和记录器的指针)。

如果您真的打算这样做,而不仅仅是为了好奇心,那么这里是一个从DefaultLogger获取的片段,其中列出了如何使用任务名称记录构建事件消息:

/**
 * Logs a message, if the priority is suitable.
 * In non-emacs mode, task level messages are prefixed by the
 * task name which is right-justified.
 *
 * @param event A BuildEvent containing message information.
 *              Must not be <code>null</code>.
 */
public void messageLogged(BuildEvent event) {
    int priority = event.getPriority();
    // Filter out messages based on priority
    if (priority <= msgOutputLevel) {

        StringBuffer message = new StringBuffer();
        if (event.getTask() != null && !emacsMode) {
            // Print out the name of the task if we're in one
            String name = event.getTask().getTaskName();
            String label = "[" + name + "] ";

答案 1 :(得分:1)

您是否尝试过-emacs命令行选项?

https://ant.apache.org/manual/running.html