Amender:
Huang Kai
E_mail: hk_sz@163.com
First, ANT use example
1.1 Copt Task via ANT submitted the recently updated file (according to the system time) file in the current directory to the specified directory
1.2 Develop Java programs with ANT
1.3 ANT combined with JUnit for software automatic test
1.4 ANT development and deployment web applications
1.5 ANT Packaging (JAR) application
1.6 ANT development EJB application
reference
1. ANT uses example 1.3 ANT combined with JUnit for software automatic test
1> The automatic process of starting basic compilation and testing with ANT binding JUnit is as follows:
★ Execute JUnit test
★ Capture the test results, record the results to the XML file or other format
★ Translate results into test report based on XSL format
★ Translate this report to HTML format
★ Send a report by email
Once the capture result, you can use the XML formatter to run the number of faults and errors for each test suite, along with the execution time of the test suite with the package and class name. For each test suite, the following information is captured:
☆ Name of the test case
☆ Duration of execution
☆ Type of fault or error (if applicable)
☆ Any fault or error details
2> Directory structure of this instance:
D: / car home directory
/ SRC source program directory
/ Classes compiled Class file directory
/ ETC Other
/ XSL XSL file directory
First create a CAR directory, SRC subdirectories, and copy the junit-noframes.xsl file from% ANT_HOME% / ETC to the D: / car / etc / xsl subdirectory.
3> Download from http://download.sourceforge.net/junit/junit3.8.zip, unzip to the D disk, copy the junit.jar file under its directory to the% Ant_home% / lib directory.
4> New Car.java and TestCar.java files in the src subdirectory.
The content of car.java is as follows: // The class that will be tested
Public Class Car
{
Public int getWheels ()
{
Return 3;
}
}
The contents of TestCar.java are as follows:
// Class to execute the test
Import junit.framework. *;
Public Class Testcar Extends Testcase
{
Protected int expectedwheels;
protected car mycar;
Public testcar (String name)
{
Super (Name);
}
protected void setup ()
{
EXPECTEDWHEELS = 4;
Mycar = new car ();
}
Public Static Test Suite ()
{
Return New TestSuite (TestCar.class);
}
Public void testGetwheels ()
{
Assertequals (expectedwheels, mycar.getwheels ());
}
}
5> in build.xml and build.properties files.
The buil.properties file content is as follows:
Src.dir = SRC
Build.dir = Classes
xsl.dir = etc / xsl
Report.dir = report
The building contents of the build.xml are as follows:
XML Version = "1.0"?>
javac>
target>
claspath>
fileset>
batchtest>
junit>
fileset>
junitreport>
target>
delete>
target>
provject>
6> Run Ant Junit in the D: / Car directory,
This generates JUnit-Noframes.html, Tests-TestSuits.xml, and TestCar.xml files in Car / Report, open JUnit-Noframes.html to view the results. Run an Ant Clean to restore the original. 1.5 ANT Packaging (JAR) application
1> Premise:
The directory structure used in this example is as follows:
D: / agn
SRC Java Source File Directory
Meta-INF configuration file directory
2> Create a Virtualage.java and MyVirtualage.java files in the src directory.
The content of Virtualage.java is as follows:
Public Final Class VirtuaLage
{
Public Static Int YeaSold (INT i)
{
Return i 1;
}
}
Myvirtualage.java is as follows:
Public class myvirtualage
{
Public static void main (string [] args)
{
INT myage = 10;
System.out.println ("My Age IS" Myage);
System.out.println ("My Virtual Age IS" Virtualage.YeaSold (myage));
}
}
3> Create build.properties and build.xml files in the AGE directory.
The building contents of the build.properties are as follows:
SRC = SRC
Classes = classes
JAR = jar
Manifest = META-INF
Author.name = KAY
The building contents of the build.xml are as follows:
XML Version = "1.0"?>
1> The directory structure used in this example is as follows:
D: / demoejb
SRC Java Source File Directory
Conf configuration file directory
2> Create ConvertRejb.java, ConverterHome.java, ConverterHome.java, ConverterHome.java, ConverterHome.java, ConverterHome.java, ConverterHome.java, CONVERTERHOME.JAVA.
The contents of the ConvertRejb.java file are as follows:
Import java.rmi.remoteexception;
Import javax.ejb.sessionbean;
Import javax.ejb.sessionContext;
Import java.math. *;
Public class converterejb imports sessionbean {
BigDecimal Yenrate = New BigDecimal ("121.6000");
BigDecimal EURORATE = New BigDecimal ("0.0077");
Public BigDecimal Dollartoyen (BigDecimal DOLLARS) {
BigDecimal Result = DOLLARS.MULTIPLY (YENRATE);
Return Result.setscale (2, BigDecimal.Round_UP);
Public BigDecimal Yentoeuro (BigDecimal Yen) {
BigDecimal result = yen.multiply (eURORATE);
Return Result.setscale (2, BigDecimal.Round_UP);
}
Public convertEREJB () {}
Public void ejbcreate () {}
Public void ejbremove () {}
Public void ejbactivate () {}
Public void ejbpassiVate () {}
Public void setsessionContext (sessioncontext sc) {}
}
The contents of the ConverterHome.java file are as follows:
Import javax.ejb.ejbhome;
Import java.io.serializable;
Import java.rmi.remoteexception;
Import javax.ejb.createException;
Import javax.ejb.ejbhome;
Public interface converTerhome Extends ejbhome {
Converter Create () throws RemoteException, CreateException;
}
The content of the Converter.java file is as follows:
Import javax.ejb.ejbobject;
Import java.rmi.remoteexception;
Import java.math. *;
Public Interface Converter Extends EJBOBJECT {
Public BigDecimal Dollartoyen (BigDecimal Dollars) throws RemoteException;
Public BigDecimal YENTOEURO (BigDecimal Yen) Throws RemoteException;
}
The CLIENT.JAVA file content is as follows:
Import java.rmi.remoteexception;
Import java.util.collection;
Import java.util.hashtable;
Import java.util.properties;
Import java.util.vector;
Import java.util.iterator;
Import javax.ejb.createException;
Import javax.ejb.duplicateKeyException;
Import javax.ejb.finderexception;
Import javax.ejb.ObjectNotFoundException;
Import javax.ejb.removeexception;
Import javax.naming.context;
Import javax.naming.initialcontext;
Import javax.naming.namingexception;
Import javax.rmi.portableremoteObject;
Import java.math.bigdecimal;
Public class client {
Private static context getinitialcontext () throws namingexception {
Try {
Properties h = new profment ();
H.PUT (Context.Initial_Context_Factory, "WebLogic.jndi.wlinitialContextFactory"); H.PUT (Context.Provider_URL, "T3: // LocalHost: 7001");
Return New InitialContext (h);
} catch (namingexception ne) {
Throw ne;
}
}
Public static void main (String [] args) {
Try {
Context initial = getinitialcontext ();
Object objref = initial.lookup ("EJB / Session / Converter");
ConverterHome Home = (ConverterHome) PortableRemoteObject.narrow (Objref, ConverterHome.Class);
Converter currencyconverter = home.create ();
BigDecimal param = New BigDecimal ("100.00");
BigDecimal amount = currencyconverter.dollartoyen (param);
System.out.println (Amount);
Amount = currencyconverter.yentoeuro (param);
System.out.println (Amount);
System.exit (0);
} catch (exception ex) {
System.err.Println ("Caught An Unexpected Exception!");
EX.PrintStackTrace ();
}
}
}
3> Create build.properties and build.xml files in the DemoEJB directory.
The building contents of the build.properties are as follows:
SRC = SRC
CONF = Conf
Classes = classes
Manifest = classes / meta-inf
JAR = jar
WebLogic.lib = C: / bea / WebLogic700 / Server / LIB
Author.name = KAY
Username = training
User.password = training
ejb.name = demoejb
WebLogic.Deploy.dir = c: / bea / user_projects / mydomain / myserver / upload
The building contents of the build.xml are as follows:
XML Version = "1.0"?> ClassPath = "$ {WebLogic.lib} /weblogic.jar" Username = "$ {username}" password = "$ {user.password}" /> serverDeploy> target> Ant use Author: Unknown Or site: http://php.igt.com.tw/Unit_116.htm Develop Java programs using ANT Author: cinc Original site: http://www.douzhe.com/bbsjh/14/434.html Automatically build test backup and release to project web with ANT implementation project Author: beyondii Or site: http://www.9cbs.net/develop/read_article.asp? Id = 20443 http://www.9cbs.net/develop/read_article.asp?id=20444 http://www.9cbs.net/develop/read_article.asp?id=20445 http://www.9cbs.net/develop/read_article.asp?id=20446 Let compilation and test process automation Author: Erik Hatcher Or site: http://www-900.ibm.com/developerWorks/cn/java/j-junitmail/ "J2EE application development (WebLogic JBuilder" Publishing House: Electronic Industry Press "THE BESTBOOK Advanced Programmer Java2" Author: Zhang Hongbin Publisher: unknown