2013-07-05 82 views
20

通过Ant任务运行javac时,是否有任何清楚说明和简单的方法来查看编译器输出?如何通过Ant任务运行javac时查看编译器输出?

这是我javac蚂蚁标签:

<javac srcdir="${myproject.src}" destdir="${myproject.class}"> 
    <!-- ... --> 
</javac> 

这里是唯一的错误信息获取:

/path/to/build.xml:42: Compile failed; see the compiler error output for details. 

的问题是,我不知道怎么看到编译器错误输出详情 ...


很少con外形元素,可以帮助:通过Eclipse

  • 蚂蚁1.6.5
  • Windows 7的64位
  • 的Java 1.6.0_20 X32
  • 启动目标

我知道有关于SO的一些相关的回答问题,但他们都没有真正回答这个简单的问题:

+0

在出现错误消息之前,你没有看到'[javac] ...'? –

+0

@ sp00m您是否从命令行运行ant时看到错误详细信息。我猜测问题与蚂蚁有关。 – Jayan

+0

如果你没有看到任何'[javac]'它可能是一个'java.lang.OutOfMemoryError:Java堆空间',参见[Stackoverflow](http://stackoverflow.com/questions/5579073/javac-java- lang-outofmemoryerror-when-running-ant-from-eclipse /) – hokr

回答

8

我认为你正在寻找的verbose="true"属性。

Asks the compiler for verbose output; defaults to no.

您已在评论中提到,这不会显示您的错误原因。那么我认为你的情况正在发生其他事情。我有一个示例项目,无论哪种方式,我的错误的原因打印。下面是输出与verbose="false"

[mkdir] Created dir: C:\Projects\MavenSandbox\target\classes 
[javac] C:\Projects\MavenSandbox\mavensandbox.xml:284: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds 
[javac] Compiling 3 source files to C:\Projects\MavenSandbox\target\classes 
[javac] C:\Projects\MavenSandbox\src\main\java\com\sandbox\Sandbox.java:8: error: cannot find symbol 
[javac]   System.out.prinln("Hello, I\'m the best!"); 
[javac]     ^
[javac] symbol: method prinln(String) 
[javac] location: variable out of type PrintStream 
[javac] 1 error 

古怪而且具体到你的代码是导致糟糕的错误消息。你能否创建一个重现错误的示例项目?如上所述,debug="true"不是您要查找的属性。

Indicates whether source should be compiled with debug information; defaults to off. If set to off, -g:none will be passed on the command line for compilers that support it (for other compilers, no command line argument will be used). If set to true, the value of the debuglevel attribute determines the command line argument.

你知道什么时候你得到堆栈跟踪,它有行号吗?这就是debug="true"所做的。如果关闭,您不会收到行号。

+1

你在哪里添加'verbose =“true”'?我遇到了同样的问题,使用Eclipse生成build.xml,它只说'somepath/build.xml:34:编译失败;有关详细信息,请参阅编译器错误输出。“我已将它添加到唯一的标记中作为属性。仍无法在任何地方看到编译器错误输出... –

0

您应该添加属性debug

<javac srcdir="${myproject.src}" destdir="${myproject.class}" debug="true> 
    <!-- ... --> 
</javac> 
+0

它不会改变任何东西(我已经在它上面了)......编译器的输出应该在哪里? – sp00m

+0

甚至'verbose' –

+0

@SotiriosDelimanolis使用'verbose',Ant的输出*更长*但它仍然不会影响编译器的输出AFAIK ... – sp00m

0

使用此

<javac srcdir="src" destdir="build/classes" debug="true"> 
      <classpath> 
       <path refid="classpath"/> 
      </classpath> 
</javac> 
1

的问题也发生在Java的编译器本身无法启动。例如,当定义的堆太大时。的IntelliJ的Java2的任务将显示在build.xml文件中的信息

Using external javac compiler 
Compilation arguments: 
... 
'-J-Xmx1600m' 
... 
Error occurred during initialization of VM 
Could not reserve enough space for object heap 
Could not create the Java virtual machine. 

和事业,在我的情况:

<property name="compiler.args" value="-J-Xmx1600m"/> 
0

我得到同样的错误信息,没有进一步的信息。问题最终成为我的一个.jar文件被损坏。替换该.jar文件解决了问题。