标签:
有如下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>
在eclipse中使用ant 执行该target 的时候,会出现如下乱码。
Buildfile: F:\androidWorkspace\Packers\build.xml
Trying to override old definition of task dex-helper
compile:
[javac] F:\androidWorkspace\Packers\custom_rules.xml:59: warning: ‘includeantruntime‘ was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
shanhy:
[java] ????: ?????????????????? Test
BUILD FAILED
F:\androidWorkspace\Packers\custom_rules.xml:64: Java returned: 1
Total 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.xml
Trying to override old definition of task dex-helper
compile:
[javac] F:\androidWorkspace\Packers\custom_rules.xml:59: warning: ‘includeantruntime‘ was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
shanhy:
[java] 错误: 找不到或无法加载主类 Test
BUILD FAILED
F:\androidWorkspace\Packers\custom_rules.xml:64: Java returned: 1
Total time: 1 second
Buildfile: F:\androidWorkspace\Packers\build.xml
Trying to override old definition of task dex-helper
compile:
[javac] F:\androidWorkspace\Packers\custom_rules.xml:59: warning: ‘includeantruntime‘ was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
shanhy:
[java] 单红宇
BUILD SUCCESSFUL
Total time: 1 second
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]);
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
eclipse中ant build 控制台乱码解决解决方法(ant执行java)
标签:
原文地址:http://blog.csdn.net/catoop/article/details/47753405