The ant build console in Eclipse solves the workaround (Ant execution Java)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.