Have the following ant target, in order to execute Java code
<target name= "Shanhy" depends= "compile" ><!--indicates the name of the Java class to invoke--><java classname= "Test" fork= "true" Failonerror= "true" ><!--indicates the class path of the Java class to invoke--><classpath path= "F:\androidWorkspace\apkPacker\bin" ></classpath></java></target>
In the above code, classname should write the Java class including the name of the package name "Com.shanhy.demo.packers.Test", I deliberately write the wrong only write "Test"
The following garbled characters will appear when using ant to execute the target in eclipse.
buildfile:f:\androidworkspace\packers\build.xmltrying to override old definition of task dex-helpercompile: [ Javac] f:\androidworkspace\packers\custom_rules.xml:59:warning: ' Includeantruntime ' is 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
In the actual project development, we may use many Chinese place, may often appear such garbled situation, causes us not to correctly judge the specific wrong reason.
The workaround is to modify the runtime output encoding of ant at run time, we add (<sysproperty key= "file.encoding" value= "UTF-8"/>), the console will be able to display Chinese correctly, as follows:
<target name= "Shanhy" depends= "compile" ><!--indicates the name of the Java class to invoke--><java classname= "Test" fork= "true" Failonerror= "true" > <sysproperty key= "file.encoding" value= "UTF-8"/><!--indicates the class path of the Java class to invoke-- ><classpath path= "F:\androidWorkspace\apkPacker\bin" ></classpath></java></target>
The output is as follows:
buildfile:f:\androidworkspace\packers\build.xmltrying to override old definition of task dex-helpercompile: [ Javac] f:\androidworkspace\packers\custom_rules.xml:59:warning: ' Includeantruntime ' is not set, defaulting to Build.sysclasspath=last; Set to False for repeatable buildsshanhy: [Java] Error: Main class Testbuild not found or cannot be loaded failedf:\androidworkspace\packers\custom_ Rules.xml:64:java Returned:1total time:1 Second
We will now modify the classname correctly, as follows:
buildfile:f:\androidworkspace\packers\build.xmltrying to override old definition of task dex-helpercompile: [ Javac] f:\androidworkspace\packers\custom_rules.xml:59:warning: ' Includeantruntime ' is not set, defaulting to Build.sysclasspath=last; Set to False for repeatable buildsshanhy: [Java] Tan Hongyu build successfultotal time:1 Second
The Java class code for the test is:
Package Com.shanhy.demo.packers;public class Test {/** * Test * * @param args * @author shanhy * @date 2015-8-18 */p Ublic static void Main (string[] args) {System.out.println (args[0]);}}
<target name= "Shanhy" depends= "compile" ><!--indicates the name of the Java class to invoke--><java classname= "Test" fork= "true" Failonerror= "true" ><!--indicates the class path of the Java class to invoke--><classpath path= "F:\androidWorkspace\apkPacker\bin" ></classpath></java></target>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The ant build console in Eclipse solves the workaround (Ant execution Java)