Use ant to compile and generate a jar package

Source: Internet
Author: User

Use ant to generate an executable JAR file. Double-click it to open the window.

1. Write a class for creating a window

PackageCom. anllin. Ant. test;

 

ImportJava. AWT. color;

ImportJava. AWT. dimension;

 

ImportJavax. Swing. jbutton;

ImportJavax. Swing. jframe;

 

Public ClassWindow

{

Public Static VoidMain (string [] ARGs)

{

Jframe frame =NewJframe ();

Frame. setsize (NewDimension (200,300 ));

Frame. setbackground (NewColor (200,200,200 ));

Frame. setalwaysontop (True);

Frame. getcontentpane (). Add (NewJbutton ("ant "));

Frame. setvisible (True);

Frame. setdefaclocloseoperation (jframe.Exit_on_close);

}

}

 

 

2. Use ant to compile and generate a jar package

<? XML version = "1.0" encoding = "UTF-8"?>

<Project name = "myantproject" basedir = "." default = "package">

<Property name = "compile" value = "compile"/>

<Property name = "Dist" value = "Dist"> </property>

<Target name = "init"> </Target>

<Target name = "preprocess" depends = "init">

<Mkdir dir = "$ {compile}"/>

<Mkdir dir = "$ {Dist}"/>

</Target>

<Target name = "compile" depends = "init, preprocess"> </Target>

<Target name = "package" depends = "compile"> </Target>

<Target name = "mycompile" depends = "preprocess">

<Javac srcdir = "src" destdir = "$ {compile}"> </javac>

</Target>

<Target name = "Dist" depends = "mycompile">

<Jar destfile = "$ {Dist}/package. Jar" basedir = "$ {compile}">

<Manifest>

<Attribute name = "Build-by" value = "$ {user. name}"/>

<Attribute name = "Main-class" value = "com. anllin. Ant. Test. Window"/>

</Manifest>

</Jar>

</Target>

</Project>

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.