本文共 2122 字,大约阅读时间需要 7 分钟。
有如下ant的target,为了执行java代码
上面代码中,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" />) 后,控制台就可以正常显示中文了,如下:
输出如下:
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]); }}
转载地址:http://jylfa.baihongyu.com/