Ant to implement Java compiler and run __java

Source: Internet
Author: User
 


Continue to learn ant today. For simplicity's sake, use ant to do a common trilogy of Java programs: writing, compiling, and running.

1 According to yesterday's learning results, to do a project should first plan the engineering structure. So first layout file structure: Src folder put source files, classes put the compiled files.
2. Write a simple source file Helloworld.java content is to print Hello world a few words then put in the SRC folder
3. Write Build.xml and place it on the same level directory as the SRC folder. The contents and comments of Build.xml are as follows:

<?xml version= "1.0" encoding= "UTF-8"?>
<project name= "HelloWorld" default= "Run" basedir= "." >

<property name= "src" value= "src"/>
<property name= "Dest" value= "Classes"/>

<!--initialization, create classes folders to prevent the compilation of good class files-->
<target name= "Init" >
<mkdir dir= "${dest}"/>
</target>

<!--compiled, Sredir indicates the original file directory, destdir indicate where to put the compiled. -->
<!--Note: Sredir does not use the indicated filename, I think the filename should default to the project name. -->
<!--denpends= "Init" means to run init this target--> first
<target name= "Compile" depends= "init" >
<javac srcdir= "${src}" destdir= "${dest}"/>
</target>

<!--running command is actually a Java command. Indicates the class name to run, and the path-->
<target name= "Run" depends= "compile" >
<java classname= "HelloWorld" classpath= "${dest}"/>
</target>

</project>

4. Enter the project directory, input ant command to complete the process of compiling to run. After modifying the source file, it is convenient to ant again directly.
so far, you've got an overview of Ant's Role and basic build process. More detailed in-depth knowledge in the future can be learned in the learning and practice and mastered.

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.