目录 | 文件 |
bin | 公共的二进制文件,以及运行脚本 |
build | 临时创建的文件,如类文件等 |
dist | 目标输出文件,如生成Jar文件等。 |
doc/javadocs | 文档。 |
lib | 需要导出的Java包 |
src | 源文件 |
<target name="core" depends="init"> <ant dir="components" target="core"/> <ant dir="waf/src" target="core"/> <ant dir="apps" target="core"/> </target> |
图2 build.xml文件的结构
<!DOCTYPE project [ <!ENTITY share-variable SYSTEM "file:../share-variable.xml"> <!ENTITY build-share SYSTEM "file:../build-share.xml"> ]> <project name="main" default="complie" basedir="."> &share-variable; &build-share; ... ... |
<target name="deploy_HelloEJB" depends="compile"> <delete dir="${temp}/ejb_make"/> <!-- 首先删除临时目录 --> <delete file="${temp}/helloEJB.jar"/> <!-- 删除WebLogic域中老版本的EJB --> <delete file="${weblogic.deploy.dest}/helloEJB.jar"/> <!-- 创建META-INF目录,放置ejb-jar.xml和weblogic-ejb-jar.xml --> <mkdir dir="${temp}/ejb_make/META-INF"/> <!-- 拷贝ejb-jar.xml和weblogic-ejb-jar.xml 到临时目录--> <copy todir="${temp}/ejb_make/META-INF"> <fileset dir="etc/baseinfo"> <include name="*.xml"/> </fileset> </copy> <!-- 拷贝所有的helloEJB类到临时目录 --> <copy todir="${temp}/ejb_make/"> <fileset dir="${dest.classes}/"> <!-- dest.classes是输出的类文件目录 --> <include name="${dest.classes}/helloEJB/**"/> </fileset> </copy> <!-- 将所有这些文件打包成helloEJB.jar --> <jar jarfile="${temp}/helloEJB.jar" basedir="${temp}/ejb_make"/> <!-- 进行weblogic.ejbc编译 --> <java classpath="${wl_cp}" classname="weblogic.ejbc" fork="yes" > <classpath> <fileset dir="lib"> <include name="*.jar" /> </fileset> </classpath> <arg value="${temp}/helloEJB.jar" /> <arg value="${temp}/helloEJB_deploy.jar" /> </java> <!-- 拷贝/发布到WebLogic的{DOMAIN}\applications目录 --> <copy file="${temp}/helloEJB_deploy.jar" todir="${weblogic.deploy.dest}"/> </target> |
<target name="run" depends="client"> <junit printsummary="yes" fork="yes" haltonfailure="yes"> <classpath> <pathelement location="client.jar" /> </classpath> <formatter type="plain" /> <test name="com.sharetop.antdemo.HelloWorldTest" /> </junit> </target> |
//HelloInfoTask.java package com.sharetop.antdemo; import org.apache.tools.ant.*; public class HelloInfoTask { private String msg; public void execute() throws BuildException { System.out.println(msg); } public void setMessage(String msg) { this.msg = msg; } } |
//HelloTask.java package com.sharetop.antdemo; import org.apache.tools.ant.*; public class HelloTask extends Task implements org.apache.tools.ant.TaskContainer { private Task info; private int count; public void execute() throws BuildException { for(int i=0;i<count;i++) info.execute(); } public void setCount(int c){ this.count=c; } public void addTask(Task t){ this.info=t; } } |
<target name="hello" depends="client"> <taskdef name="hello" classname="com.sharetop.antdemo.HelloTask" classpath="client.jar"/> <taskdef name="helloinfo" classname="com.sharetop.antdemo.HelloInfoTask" classpath="client.jar"/> <hello count="3" > <helloinfo message="hello world" /> </hello> </target> |