2013-07-05 83 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文件解決了問題。