1. Trang chủ
  2. » Công Nghệ Thông Tin

Ant tutorial

218 696 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Ant Installing ANT for Windows 7
Thể loại Thực hành
Định dạng
Số trang 218
Dung lượng 6,3 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Content • Preparing the project • Enhance the build file • Enhance the build file • Using external libraries • Resources Preparing the project We want to separate the source from the gen

Trang 1

Installing ANT for Windows 7

2 Unzip it and rename it to ant

you uncompressed, to do it on command prompt type this (Assume Ant is installed in E :\ant\ )

-Choose Advanced Tab

-Press Environtmen Variables Button

-In the System Variables, click New Button

Give the Variable Name:ANT_HOME

Give the Value: E:\ant

Click OK

Then,we’ll add new ANT_HOME path,

And Click again on New Button if you do not have ‘path’ Variable in there, if so select it and edit as

Give the Variable Name:path

Give the Value D:\Program Files\Java\jdk1.6.0_03\bin;%ANT_HOME%\bin

Click OK

4 Check wheter ANT works correctly or not

In the command prompt, type:

ant -version

I got Apache Ant version 1.8.1 compiled on April 30 2010

Trang 2

Thực hành : Tạo môi trường biên dịch java và ant Thiết lập môi trường java

Trang 3

Thiết lập môi trường ant.

Trang 5

Application Demo

Trang 6

Tutorial: Hello World with Apache Ant

This document provides a step by step tutorial for starting java programming with Apache Ant It

does not contain deeper knowledge about Java or Ant This tutorial has the goal to let you see,

how to do the easiest steps in Ant

Content

• Preparing the project

• Enhance the build file

• Enhance the build file

• Using external libraries

• Resources

Preparing the project

We want to separate the source from the generated files, so our java source files will be in src

folder All generated files should be under build, and there splitted into several subdirectories for the individual steps: classes for our compiled files and jar for our own JAR-file

win-syntax - translate to your shell):

md src

The following simple Java class just prints a fixed message out to STDOUT, so just write this

package oata;

public class HelloWorld {

public static void main(String[] args) {

javac -sourcepath src -d build\classes src\oata\HelloWorld.java

java -cp build\classes oata.HelloWorld

which will result in

Hello World

Trang 7

Creating a jar-file is not very difficult But creating a startable jar-file needs more steps: create a

manifest-file containing the start class, creating the target directory and archiving the files

echo Main-Class: oata.HelloWorld>myManifest

md build\jar

jar cfm build\jar\HelloWorld.jar myManifest -C build\classes

java -jar build\jar\HelloWorld.jar

Note: Do not have blanks around the >-sign in the echo Main-Class instruction because it would falsify it!

Four steps to a running application

After finishing the java-only step we have to think about our build process We have to compile

our code, otherwise we couldn't start the program Oh - "start" - yes, we could provide a target

for that We should package our application Now it's only one class - but if you want to provide

a download, no one would download several hundreds files (think about a complex Swing GUI - so let us create a jar file A startable jar file would be nice And it's a good practise to have a "clean" target, which deletes all the generated stuff Many failures could be solved just by

Trang 8

ant compile

ant jar

ant run

Or shorter with

ant compile jar run

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

Enhance the build file

Now we have a working buildfile we could do some enhancements: many 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 would be addressed with properties, the third with a special property

-an attribute of the <project>-tag -and the fourth problem c-an 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.dir}/classes"/>

<property name="jar.dir" value="${build.dir}/jar"/>

<property name="main-class" value="oata.HelloWorld"/>

Trang 9

<target name="run" depends="jar">

<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/> </target>

<target name="clean-build" depends="clean,jar"/>

<target name="main" depends="clean,run"/>

[mkdir] Created dir: C:\ \build\classes

[javac] Compiling 1 source file to C:\ \build\classes

jar:

[mkdir] Created dir: C:\ \build\jar

[jar] Building jar: C:\ \build\jar\HelloWorld.jar

run:

[java] Hello World

main:

BUILD SUCCESSFUL

Trang 10

Using external libraries

Somehow told us not to use syso-statements For log-Statements we should use a Logging-API - customizable on a high degree (including switching off during usual life (= not development) execution) We use Log4J for that, because

• it is not part of the JDK (1.4+) and we want to show how to use external libs

• it can run under JDK 1.2 (as Ant)

• it's highly configurable

• it's from Apache ;-)

Logging's Homepage Create the lib directory and extract the log4j-1.2.9.jar into that

lib-directory After that we have to modify our java source to use that library and our buildfile so that this library could be accessed during compilation and run

Working with Log4J is documented inside its manual Here we use the MyApp-example from the

Short Manual [2] First we have to modify the java source to use the logging framework:

package oata;

import org.apache.log4j.Logger;

import org.apache.log4j.BasicConfigurator;

public class HelloWorld {

static Logger logger = Logger.getLogger(HelloWorld.class);

public static void main(String[] args) {

Don't try to run ant - you will only get lot of compiler errors Log4J is not inside the classpath so

we have to do a little work here But do not change the CLASSPATH environment variable! This is only for this project and maybe you would break other environments (this is one of the most famous mistakes when working with Ant) We introduce Log4J (or to be more precise: all libraries (jar-files) which are somewhere under .\lib) into our buildfile:

<project name="HelloWorld" basedir="." default="main">

Trang 11

<target name="run" depends="jar">

<java fork="true" classname="${main-class}">

In this example we start our application not via its Main-Class manifest-attribute, because we

could not provide a jarname and a classpath So add our class in the red line to the already

defined path and start as usual Running ant would give (after the usual compile stuff):

[java] 0 [main] INFO oata.HelloWorld - Hello World

What's that?

[java] Ant task running at the moment

[main] the running thread from our application

INFO log level of that statement

oata.HelloWorld source of that statement

- separator

Hello World the message

For another layout have a look inside Log4J's documentation about using other PatternLayout's.

Configuration files

Why we have used Log4J? "It's highly configurable"? No - all is hard coded! But that is not the

simple, but hard coded configuration More comfortable would be using a property file In the java source delete the BasicConfiguration-line from the main() method (and the related import-statement) Log4J will search then for a configuration as described in it's manual Then create a

Trang 12

new file src/log4j.properties That's the default name for Log4J's configuration and using that name would make life easier - not only the framework knows what is inside, you too!

System.out.println() :-) Oooh kay - but we haven't finished yet We should deliver the

configuration file, too So we change the buildfile:

Testing the class

In this step we will introduce the usage of the JUnit [3] testframework in combination with Ant Because Ant has a built-in JUnit 3.8.2 you could start directly using it Write a test class in

public class HelloWorldTest extends junit.framework.TestCase {

public void testNothing() {

}

public void testWillAlwaysFail() {

fail("An error message");

Trang 13

<path id="application" location="${jar.dir}/${ant.project.name}.jar"/>

<target name="run" depends="jar">

<java fork="true" classname="${main-class}">

We reuse the path to our own jar file as defined in run-target by giving it an ID and making it

"FAILED" or "PASSED" message How much tests failed? Some errors? Printsummary lets us know The classpath is set up to find our classes To run tests the batchtest here is used, so you

common naming scheme

After a ant junit you'll get:

junit:

[junit] Running HelloWorldTest

[junit] Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 0,01 sec

[junit] Test HelloWorldTest FAILED

BUILD SUCCESSFUL

We can also produce a report Something that you (and other) could read after closing the shell There are two steps: 1 let <junit> log the information and 2 convert these to something readable (browsable)

<property name="report.dir" value="${build.dir}/junitreport"/>

Trang 14

<target name="junit" depends="jar">

<batchtest fork="yes" todir="${report.dir}">

<fileset dir="${src.dir}" includes="*Test.java"/>

Because we would produce a lot of files and these files would be written to the current directory

by default, we define a report directory, create it before running the junit and redirect the

report directory Now you can open the ${report.dir}\index.html and see the result (looks something like JavaDoc)

Personally I use two different targets for junit and junitreport Generating the HTML report needs some time and you dont need the HTML report just for testing, e.g if you are fixing an error or a integration server is doing a job

Trang 15

Example 1:Create an project ant demo.

Create an java project.

Main.java

package org.quangthao.common;

import javax.swing.JFrame;

public class Main {

public static void main(String[] args){

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

< echo > runing </ echo >

Trang 16

< java classname ="org.quangthao.common.Main">

</ java >

</ target >

Total time: 933 milliseconds

Or use command line :

Trang 17

Commented :Ta thấy ,project có giá trị default là run nên nó sẽ thực hiện target run trước,ta xét đến target có tên run có attribute depends là compile => nó sẽ thực hiện target có tên compile trước,sau đó đến target run.

Example 2:Create an web application with jboss 7.1.1 AS

Trang 18

Sau khi build xong,trong thư mục deployments của jboss có thêm file sau:

Trang 19

Khởi chạy server

Browse

Trang 20

Example 3:Create an ant project (war and deployment,start and stop Tomcat)

Trang 21

build.xml

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

<project default ="warTarget" name ="Ant web demo with tomcat">

<property name ="tomcat" value ="D:/software/apache-tomcat-7.0.42"></property>

<property name ="tomcat.deployment" value ="${tomcat}/webapps"></property>

<property name ="tomcat.bin" value ="${tomcat}/bin"></property>

<property name ="base" value ="."></property>

<property name ="source" value ="${base}/src"></property>

<target name ="warTarget">

<war warfile ="ant-web-demo-tomcat.war" needxmlfile ="file">

<fileset dir ="${base}/WebContent"/>

</war>

<antcall target ="deployTarget"/>

</target>

<target name ="deployTarget">

<copy file ="${base}/ant-web-demo-tomcat.war" todir ="${tomcat.deployment}"></copy>

<antcall target ="startTomcat"/>

</target>

<target name ="startTomcat">

<exec executable ="${tomcat.bin}/startup.bat"></exec>

</target>

<target name ="stopTomcat">

<exec executable ="${tomcat.bin}/shutdown.bat"></exec>

</target>

</project>

Trang 22

Khi start server tomcat thì nó sẽ bật ra một của sổ nữa như sau :

Trang 23

Để stop server Tomcat ta gõ thêm lệnh sau vào cửa sổ command prompt : ant stopTomcat

note :stopTomcat là tên của target có exec thực hiện stop server tomcat

Trang 24

Example 3:add web.xml file,set environment variable,war and deploy ,start and stop tomcat.

Trang 26

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

<project default= "warTarget" name= "Ant web demo tomcat 2" >

<property name= "tomcat" value= "D:/software/apache-tomcat-7.0.42" ></property>

<property name= "tomcat.bin" value= "${tomcat}/bin" ></property>

<property name= "tomcat.deployment" value= "${tomcat}/webapps" ></property>

<property name= "base" location= "." />

<property name= "source" value= "${base}/src" ></property>

<property name= "webcontent" value= "${base}/WebContent" ></property>

<target name= "warTarget" >

<war warfile= "${base}/staging/ant-web-demo-tomcat2.war" webxml= "$

{source}/metadataFile/web.xml" > //warfile :nơi chứa file và tên file war được tạo ra webxml:chọn file web.xml là file cấu hình cho web

<fileset dir= "${webcontent}" ></fileset> //thiết lập nơi chứa nội dung web

<fileset dir= "${source}/webFile" ></fileset> //thiết lập nơi chứa nội dung web

</war>

<antcall target= "deployTarget" ></antcall>

</target>

<target name= "deployTarget" >

<copy file= "${base}/staging/ant-web-demo-tomcat2.war" todir= "${tomcat.deployment}" ></copy>

<antcall target= "startTomcat" ></antcall>

</target>

<target name= "startTomcat" >

<exec executable= "${tomcat.bin}/startup.bat" >

<env key= "CATALINA_HOME" value= "${tomcat}" /> //thiết lập biến môi trường cho tomcat

</exec>

</target>

<target name= "stopTomcat" >

<exec executable= "${tomcat.bin}/shutdown.bat" >

<env key= "CATALINA_HOME" value= "${tomcat}" />

</exec>

</target>

</project>

Trang 28

Example 4:instead use property tag in

build.xml then we can use properties file to declare key and value

build.xml

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

<project default= "warTarget" name= "Ant web demo tomcat 2"

<property file= "./build.properties" ></property>

<target name= "warTarget" >

<war warfile= "${base}/staging/ant-web-demo-tomcat2.war" webxml= "$

{source}/metadataFile/web.xml" >

<fileset dir= "${webcontent}" ></fileset>

<fileset dir= "${source}/webFile" ></fileset>

</war>

<antcall target= "deployTarget" ></antcall>

</target>

<target name= "deployTarget" >

<copy file= "${base}/staging/ant-web-demo-tomcat2.war" todir= "${tomcat.deployment}" ></copy>

<antcall target= "startTomcat" ></antcall>

</target>

<target name= "startTomcat" >

<exec executable= "${tomcat.bin}/startup.bat" >

<env key= "CATALINA_HOME" value= "${tomcat}" />

</exec>

</target>

Trang 29

<target name= "stopTomcat" >

<exec executable= "${tomcat.bin}/shutdown.bat" >

<env key= "CATALINA_HOME" value= "${tomcat}" />

</exec>

</target>

</project>

Result:

We will be result as example 3.

Example 5:Config to include library files in the war file.

<war warfile= "${base}/${project.name}.war" webxml= "${source.web.dir}/WEB-INF/web.xml" >

<fileset dir= "${source.web.dir}" ></fileset>

<lib dir= "${base}/lib" >

<include name= "mysql-connector-java-5.1.6.jar" /> //select a library file

<include name= "*/*.*" /> //select many file

</lib>

</war>

Example 6:Run một file java cùng với file java đã biên dịch và thư viện cần thiết.

<target name= "run" >

<java classname= "org.quangthao.common.TestConnectMySQL" >

<classpath path= "${basedir}/bin"

<pathelement location= "${basedir}/lib/mysql-connector-java-5.1.6.jar" />

</classpath>

</java>

</target>

Trong trường hợp file thư việc nhiều thì ta có thể dùng như sau :

<path id= "classpath" >

<fileset dir= "${basedir}/lib" includes= "**/*.jar" />

</path>

<target name= "run" >

<java classname= "org.quangthao.common.TestConnectMySQL" >

<classpath path= "${basedir}/bin"

<path refid= "classpath" ></path>

</classpath>

</java>

Trang 30

<path id= "classpath" >

<fileset dir= "${base}/lib" includes= "**/*.jar" />

<fileset dir= "${tomcat}/lib" includes= "**/*.jar" ></fileset>

</path>

<target name= "compile" >

<mkdir dir= "${base}/bin" />

<javac includeantruntime= "false" srcdir= "${base}/src" destdir= "${base}/bin" >

<classpath refid= "classpath" > </classpath>

</javac>

<copy todir= "${base}/bin" >

<fileset dir= "${base}/src" excludes= "java/**" ></fileset>

Trang 31

<project default= "run" name= "Ant web demo tomcat 2" basedir= "." >

<property file= "./build.properties" ></property>

<path id= "classpath" >

<fileset dir= "${base}/lib" includes= "**/*.jar" />

<fileset dir= "${tomcat}/lib" includes= "**/*.jar" ></fileset>

</path>

<target name= "clean-tomcat" >

<delete dir= "${tomcat.deployment}/${project.name}" ></delete>

<delete file= "${tomcat.deployment}/${project.name}.war" ></delete>

</target>

<target name= "clean" >

<delete dir= "${base}/bin" ></delete>

<delete dir= "${base}/build" ></delete>

<target name= "setup" description= "Creates the ${base}/bin and ${base}/build directories" >

<mkdir dir= "${base}/build" />

<mkdir dir= "${base}/bin" />

</target>

<target name= "compile" >

<mkdir dir= "${base}/bin" />

<javac includeantruntime= "false" srcdir= "${base}/src" destdir= "${base}/bin" >

<classpath refid= "classpath" >

</classpath>

</javac>

</target>

<target name= "jar" depends= "compile" >

<mkdir dir= "${base}/build/jar" />

<jar destfile= "${base}/build/jar/${project.name}.jar" basedir= "${base}/bin" >

Trang 32

Example 9: If you are running an Ant build file with a different name, then launch it with this command line

Trang 33

Example 10 :Đóng gói phần mềm có giao diện với ant.

Trang 34

waiting setVisible(false);

this.setIconImage(new ImageIcon(getClass().getResource( "Programs-Windows-icon.png" )).getImage()); }

@SuppressWarnings ( "unchecked" )

// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents

private void initComponents() {

jPanel3 = new javax.swing.JPanel();

cmdProcessing = new javax.swing.JButton();

jPanel2 = new javax.swing.JPanel();

jLabel10 = new javax.swing.JLabel();

uw1 = new javax.swing.JTextField();

jLabel11 = new javax.swing.JLabel();

uw2 = new javax.swing.JTextField();

jLabel12 = new javax.swing.JLabel();

uw3 = new javax.swing.JTextField();

jPanel1 = new javax.swing.JPanel();

jLabel9 = new javax.swing.JLabel();

jLabel1 = new javax.swing.JLabel();

jLabel13 = new javax.swing.JLabel();

numberOfLoop = new javax.swing.JTextField();

jLabel14 = new javax.swing.JLabel();

aboutOfNN = new javax.swing.JTextField();

jScrollPane1 = new javax.swing.JScrollPane();

table = new javax.swing.JTable();

waiting = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setTitle( "PERCEPTION" );

Trang 35

cmdProcessing setText( "Processing" );

cmdProcessing addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

cmdProcessingActionPerformed(evt);

}

});

jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Update" , javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,

javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font( "Times New Roman" , 0, 13))); // NOI18N

uw3 setEditable(false);

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout( jPanel2 );

addComponent( uw1 , javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)))

addContainerGap(47, Short.MAX_VALUE)))

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Training" , javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,

javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font( "Times New Roman" , 0, 13))); // NOI18N

jLabel8 setText( "Disired" );

jLabel9 setText( "Rate" );

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout( jPanel1 );

addComponent( tw3 , javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)

addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

Trang 36

addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

addComponent( tw2 , javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)

addGap(0, 0, Short.MAX_VALUE))

addComponent( tw1 , javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)

addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)

jLabel1 setFont(new java.awt.Font( "Times New Roman" , 1, 18)); // NOI18N

jLabel1 setText( "TRAINING WITH PERCEPTION" );

jLabel13 setText( "Number of loops" );

numberOfLoop setEditable(false);

jLabel14 setText( "About of NN" );

aboutOfNN setEditable(false);

table setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

{null, null, null, null},

{null, null, null, null},

{null, null, null, null},

{null, null, null, null}

jScrollPane1 setViewportView( table );

waiting setText( "Waiting " );

javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout( jPanel3 );

Trang 37

addComponent( jScrollPane1 , javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)

addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

waiting setVisible(true);

//Khởi tạo header cho bảng

Vector<String> colHeaders=new Vector<String>();

int dem=0;int alpha=20;

//lấy các giá trị từ trong hộp textbox để gán cho các biến đầu và o x1,x2,x3 Giá trị các tr�ng số w1,w2,w3

waiting setVisible(false);

//set model cho bảng

Trang 38

* @param args the command line arguments

*/

public static void main(String args[]) {

/* Set the Nimbus look and feel */

//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(Home.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

}

//</editor-fold>

/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new Home().setVisible(true);

}

});

}

// Variables declaration - do not modify//GEN-BEGIN:variables

private javax.swing.JTextField aboutOfNN ;

private javax.swing.JButton cmdProcessing ;

private javax.swing.JLabel jLabel1 ;

private javax.swing.JLabel jLabel10 ;

private javax.swing.JLabel jLabel11 ;

private javax.swing.JLabel jLabel12 ;

private javax.swing.JLabel jLabel13 ;

private javax.swing.JLabel jLabel14 ;

private javax.swing.JLabel jLabel2 ;

private javax.swing.JLabel jLabel3 ;

private javax.swing.JLabel jLabel4 ;

private javax.swing.JLabel jLabel5 ;

private javax.swing.JLabel jLabel6 ;

private javax.swing.JLabel jLabel7 ;

private javax.swing.JLabel jLabel8 ;

private javax.swing.JLabel jLabel9 ;

private javax.swing.JPanel jPanel1 ;

private javax.swing.JPanel jPanel2 ;

private javax.swing.JPanel jPanel3 ;

private javax.swing.JScrollPane jScrollPane1 ;

private javax.swing.JTextField uw1 ;

private javax.swing.JTextField uw2 ;

private javax.swing.JTextField uw3 ;

private javax.swing.JLabel waiting ;

// End of variables declaration//GEN-END:variables

public static void main(String[] args){

}

}

Trang 39

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<project basedir= "." default= "build" name= "SpringProject" >

<property name= "src.dir" value= "${basedir}/src" ></property>

<property name= "build" value= "${basedir}/build" ></property>

<property name= "classes" value= "${build}/classes" ></property>

<property name= "project.name" value= "springproject" ></property>

<property name= "jar.name" value= "springproject1.jar" ></property>

<path id= "classpath" >

<fileset dir= "${basedir}" includes= "**/*.jar" ></fileset>

</path>

<target name= "clean" >

<delete dir= "${build}" ></delete>

</target>

<target name= "compile" >

<mkdir dir= "${classes}" />

<javac srcdir= "${src.dir}" destdir= "${classes}"

includeantruntime= "false" source= "1.6" target= "1.6" fork= "true" debug= "true" >

<classpath refid= "classpath" >

</classpath>

</javac>

</target>

<target name= "build" depends= "clean,compile" >

<delete file= "${build}/${jar.name}" ></delete>

<jar destfile= "${build}/${jar.name}" >

<fileset dir= "${classes}" ></fileset>

<fileset dir= "${src.dir}" > </fileset>

Total time: 2 seconds

Run file jar ta được kết quả sau :

Trang 40

Example 11 :Đóng gói một ứng dụng web thành file war

Ngày đăng: 06/05/2014, 13:50

Xem thêm

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w