Enhance the Build File

Source: Internet
Author: User
Enhance the Build File

Now we have a working buildfile we cocould do some enhancements: runtime time you are referencing the same directories, main-class and jar-name are hard coded, and while invocation you have to remember the right order of Build Steps.

The first and second point wocould be addressedProperties, The third with a special property-an attribute of the <project>-tag and the fourth problem can be solved using dependencies.

<Project name = "helloworld" basedir = ". "default =" Main "> <property name =" src. dir "value =" src "/> <property name =" build. dir "value =" build "/> <property name =" classes. dir "value =" build/classes "/> <property name =" jar. dir "value =" build/jar "/> <property name =" Main-class "value =" oata. helloworld "/> <target name =" clean "> <Delete dir =" build "/> </Target> <target name =" compile "> <mkdir dir =" $ {classes. dir} "/> <javac srcdir =" src "destdir =" $ {classes. dir} "/> </Target> <target name =" jar "depends =" compile "> <mkdir dir =" $ {jar. dir} "/> <jar destfile =" $ {jar. dir}/apache-ant.jar "basedir =" $ {classes. dir} "> <manifest> <attribute name =" Main-class "value =" $ {main-class} "/> </manifest> </jar> </Target> <target name = "run" depends = "jar"> <Java jar = "$ {jar. dir}/apache-ant.jar "fork =" true "/> </Target> <target name =" Clean-build "depends =" clean, jar "/> <target name =" Main "depends =" clean, Run "/> </Project>

Now it's easier, just doAntAnd you will get

 
Buildfile: build. xmlclean: compile: [mkdir] created dir: C :\... \ build \ Classes [javac] compiling 1 source file to c :\... \ build \ classesjar: [mkdir] created dir: C :\... \ build \ jar [jar] building jar: C :\... \ build \ jar \ helloworld. jarrun: [Java] Hello worldmain: build successful

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.