2、简化后的脚本内容,在hello-jaxws目录下新建一个buildtest.xml文件,内容为
<?xml version="1.0" encoding="UTF-8"?>
<project name="hello-jaxws" default="all" basedir=".">
<!-- javaee安装目录的设置,代替了原来脚本中的导入语句 -->
<property name="javaee.home" value = "d:/Sun/SDK"/>
<property name="javaee.domaindir" value="${javaee.home}/domains/domain1"/>
<property name="javaee.server.name" value="localhost"/>
<property name="javaee.server.port" value="8080"/>
<!-- 设置发布目录和类的输出目录 -->
<property name="autodeploydir" value="${javaee.domaindir}/autodeploy"/>
<property name="classesdir" value="./build"/>
<!-- 设置java类库路径 -->
<path id="classpath">
<pathelement location="${javaee.home}/lib/j2ee.jar"/>
<pathelement location="${classesdir}"/>
</path>
<target name="all" depends="run-client">
<!--antcall target="restore"/-->
</target>
<target name="run-client" depends="compile-client,run-client-windows" />
<!-- 运行测试类,为项目的最后一个步骤-->
<target name="run-client-windows">
<exec executable="${javaee.home}/bin/appclient.bat" dir="${classesdir}">
<arg value="client.Client" />
</exec>
</target>
<!-- 编译测试webservice的客户类,为项目的第三个步骤,本步骤的输出文件为
${classesdir}/client/Client.class
-->
<target name="compile-client" depends="get-artifacts">
<javac srcdir="./src/client" destdir="${classesdir}">
<classpath refid="classpath" />
</javac>
</target>
<target name="get-artifacts" depends="compile-deploy-service,get-artifacts-windows"/>
<!-- 本步骤的目的是生成客户端的stub文件,是项目的第二个步骤,本步骤的输出文件为
在${classesdir}下面自动生成了如下的文件
GetHello.java
GetHelloResponse.java
Hello.java
HelloService.java
ObjectFactory.java
package-info.java
package-info.class
GetHello.class
GetHelloResponse.class
Hello.class
HelloService.class
ObjectFactory.class
-->
<target name="get-artifacts-windows">
<exec executable="${javaee.home}/bin/wsimport.bat">
<arg line="-keep -d ${classesdir} http://${javaee.server.name}:${javaee.server.port}/Hello/HelloService?WSDL" />
</exec>
</target>
<!-- 本步骤的目的是编译服务器类,并自动产生wsdl.是项目的第一个步骤,本步骤的主要输出文件为
${autodeploydir}\endpoint\Hello.class
${autodeploydir}\domain1\autodeploy\endpoint\Hello.class_deployed
在d:\Sun\SDK\domains\domain1\applications\j2ee-modules
下建立一个endpoint_Hello目录,
在d:\Sun\SDK\domains\domain1\generated\ejb\j2ee-modules建立一个
endpoint_Hello目录,这个目录下又建立了一个endpoint\jaxws目录,里面有如下内容
GetHello.java
GetHelloResponse.java
GetHello.class
GetHelloResponse.class
在D:\Sun\SDK\domains\domain1\generated\xml\j2ee-modules\下建立一个
endpoint_Hello目录,这个目录下又有一个WEB-INF子目录,内容为
wsdl子目录
sun-web.xml 文件
web.xml 文件
webservices.xml 文件
wsdl子目录下又有两个文件
HelloService.wsdl
HelloService_schema1.xsd
当我们在浏览器输入http://localhost:8080/Hello/HelloService?WSDL时,显示的正是
这个domains\domain1\generated\xml\j2ee-modules\endpoint_Hello\WEB-INF\wsdl
文件的内容
-->
<target name="compile-deploy-service"> <mkdir dir="${classesdir}" /> <echo message="${javaee.home}" /> <javac srcdir="./src" includes="endpoint/**" destdir="${autodeploydir}" classpath="${javaee.home}/lib/j2ee.jar" /> <waitfor maxwait="100" maxwaitunit="second"> <or> <available file="${autodeploydir}/endpoint/Hello.class_deployed"/> <available file="${autodeploydir}/endpoint/Hello.class_deployFailed"/> </or> </waitfor> <condition property="deploy_succeeded"> <available file="${autodeploydir}/endpoint/Hello.class_deployed"/> </condition> <condition property="deploy_failed"> <available file="${autodeploydir}/endpoint/Hello.class_deployFailed"/> </condition> </target>
<!-- 以下的任务用于清理和卸载--> <target name="clean"> <delete dir="${classesdir}"/> </target> <target name="restore"> <delete> <fileset dir="${autodeploydir}/endpoint" includes="Hello*.*"/> </delete> </target> <target name="undeploy"> <antcall target="restore"/> </target> </project>
3、运行结果
在myeclipse里执行这个刚才编写的buildtest.xml脚本,console里的输出为
Buildfile: D:\Sun\SDK\samples\javaee5\webservices\hello-jaxws\buildtest.xml
compile-deploy-service:
[mkdir] Created dir: D:\Sun\SDK\samples\javaee5\webservices\hello-jaxws\build
[echo] d:/Sun/SDK
[javac] Compiling 1 source file to D:\Sun\SDK\domains\domain1\autodeploy
get-artifacts-windows:
get-artifacts:
compile-client:
[javac] Compiling 1 source file to D:\Sun\SDK\samples\javaee5\webservices\hello-jaxws\build
run-client-windows:
[exec] Hello result = Hello Administrator!
run-client:
all:
BUILD SUCCESSFUL
Total time: 50 seconds
也执行成功
| 第1页: 精简后的ant脚本 | 第2页: 一个通用的ant脚本 |