Four steps to a running application

Source: Internet
Author: User

Package oata;

Public class helloworld {
Public static void main (string [] ARGs ){
System. Out. println ("Hello World ");
}
}

After finishing the Java-only step we have to think about our build process. WeHaveTo compile our code, otherwise we couldn't start the program. Oh-"start"-Yes, We cocould provide a target for that. WeShocouldPackage our application. now it's only one class-but if you want to provide a download, no one wocould download several hundreds files... (think about a complex swing Gui-so let us create a jar file. A startable JAR file wocould be nice... and it's a good practice to have a "clean" target, which deletes all the generated stuff. failed failures cocould be solved just by a "clean build ".

By default ant usesBuild. xmlAs the name for a buildfile, so our. \ Build. xmlWocould be:

 
<Project> <target name = "clean"> <Delete dir = "build"/> </Target> <target name = "compile"> <mkdir dir = "build/classes "/> <javac srcdir =" src "destdir =" build/classes "/> </Target> <target name =" jar "> <mkdir dir =" build/jar" /> <jar destfile = "build/JAR/helloworld. jar "basedir =" build/classes "> <manifest> <attribute name =" Main-class "value =" oata. helloworld "/> </manifest> </jar> </Target> <target name =" run "> <Java jar =" build/JAR/helloworld. jar "fork =" true "/> </Target> </Project>

Now you can compile, package and run the application

 
Ant compileant jarant run

Or shorter

 
Ant compile jar run

While having a look at the buildfile, we will see some similar steps between ANT and the Java-only commands:

Java-only Ant
MD build \ Classes javac-sourcepath Src-d build \ Classes SRC \ oata \ helloworld. java echo main-class: oata. helloworld> mf md build \ Jar CFM build \ jar \ helloworld. jar mf-C build \ Classes. java-jar build \ jar \ helloworld. jar
 
      
       
        
       
      
      
       
        
       
      
      

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.