eclipse中ant build 控制台亂碼解決解決方案(ant執行java)

來源:互聯網
上載者:User

標籤:

有如下ant的target,為了執行java代碼

<target name="shanhy" depends="compile"><!-- 指明要調用的java類的名稱 --><java classname="Test" fork="true" failonerror="true"><!-- 指明要調用的java類的class路徑 --><classpath path="F:\androidWorkspace\apkPacker\bin"></classpath></java></target>

上面代碼中,classname應該寫java類包括包名的名稱“ com.shanhy.demo.packers.Test ”,我故意寫錯唯寫“ Test ”

在eclipse中使用ant 執行該target  的時候,會出現如下亂碼。

Buildfile: F:\androidWorkspace\Packers\build.xmlTrying to override old definition of task dex-helpercompile:    [javac] F:\androidWorkspace\Packers\custom_rules.xml:59: warning: ‘includeantruntime‘ was not set, defaulting to build.sysclasspath=last; set to false for repeatable buildsshanhy:     [java] ????: ?????????????????? TestBUILD FAILEDF:\androidWorkspace\Packers\custom_rules.xml:64: Java returned: 1Total time: 1 second

在實際項目開發中,我們可能會用到很多中文的地方,可能會經常出現這樣亂碼的情況,導致我們無法正確的判斷具體的錯誤原因。

解決方案就是 在運行時修改ant 的運行時輸出編碼,我們添加(<sysproperty key="file.encoding" value="UTF-8" />) 後,控制台就可以正常顯示中文了,如下:


<target name="shanhy" depends="compile"><!-- 指明要調用的java類的名稱 --><java classname="Test" fork="true" failonerror="true">                        <sysproperty key="file.encoding" value="UTF-8" /><!-- 指明要調用的java類的class路徑 --><classpath path="F:\androidWorkspace\apkPacker\bin"></classpath></java></target>

輸出如下:

Buildfile: F:\androidWorkspace\Packers\build.xmlTrying to override old definition of task dex-helpercompile:    [javac] F:\androidWorkspace\Packers\custom_rules.xml:59: warning: ‘includeantruntime‘ was not set, defaulting to build.sysclasspath=last; set to false for repeatable buildsshanhy:     [java] 錯誤: 找不到或無法載入主類 TestBUILD FAILEDF:\androidWorkspace\Packers\custom_rules.xml:64: Java returned: 1Total time: 1 second

我們現在將 classname 修改正確,如下:

Buildfile: F:\androidWorkspace\Packers\build.xmlTrying to override old definition of task dex-helpercompile:    [javac] F:\androidWorkspace\Packers\custom_rules.xml:59: warning: ‘includeantruntime‘ was not set, defaulting to build.sysclasspath=last; set to false for repeatable buildsshanhy:     [java] 單紅宇BUILD SUCCESSFULTotal time: 1 second

測試的Java 類代碼為:

package com.shanhy.demo.packers;public class Test {/** * 測試 *  * @param args * @author SHANHY * @date   2015-8-18 */public static void main(String[] args) {System.out.println(args[0]);}}











<target name="shanhy" depends="compile"><!-- 指明要調用的java類的名稱 --><java classname="Test" fork="true" failonerror="true"><!-- 指明要調用的java類的class路徑 --><classpath path="F:\androidWorkspace\apkPacker\bin"></classpath></java></target>

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

eclipse中ant build 控制台亂碼解決解決方案(ant執行java)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.