在用eclipes開發(fā)web service的時(shí)候,經(jīng)常會(huì)用到j(luò)ava2wsdl,wsdl2java等命令,axis在發(fā)布的時(shí)候提供了相應(yīng)的ant task,并放到了axis-ant.jar中。
按照axis的ant相關(guān)文檔配置的時(shí)候,需要引入相應(yīng)的ant task,我在做這個(gè)配置的時(shí)候遇到了些障礙,開始的build.xml如下所示:
<?xml version="1.0"?>
<project default="axis" basedir=".">
<property name="axis.home" location="../" />
<path id="axis.classpath">
<fileset dir="${axis.home}/WebRoot/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="${axis.home}/WebRoot/WEB-INF/classes">
<include name="**/*.class" />
</fileset>
</path>
<taskdef resource="axis-tasks.properties" classpathref="/axis.classpath" />
<target name="init" />
<target name="axis">
<axis-java2wsdl
classname="axis.service.SimpleObjectCreator"
location="http://localhost:8080/axis/services/SimpleObjectCreator"
namespace="service.axis"
output="simpleObject.wsdl"
style="RPC"
extraclasses="axis.bean.SimpleObject"
>
<classpath refid="axis.classpath"/>
</axis-java2wsdl>
<axis-wsdl2java all="true"
url="simpleObject.wsdl"
deployscope="Request"
output="${axis.home}/src"
serverside="true"
skeletondeploy="false"
testcase="true"
noimports="false"
typemappingversion="1.2"
/>
</target>
<target name="deploy">
<axis-admin
port="8080"
hostname="localhost"
failonerror="true"
servletpath="axis/services/AdminService"
debug="true"
xmlfile="${axis.home}\src\axis\service\deploy.wsdd"
/>
</target>
</project>
在執(zhí)行ant的時(shí)候,總是報(bào)
java.util.zip.ZipException: error in opening zip file
的錯(cuò)誤,百思不得其解,后來找到了錯(cuò)誤的原因,原來出在
<path id="axis.classpath">...</path>
的定義上,因?yàn)檫@里包含
<fileset dir="${axis.home}/WebRoot/WEB-INF/classes">
<include name="**/*.class" />
</fileset>
部分,<taskdef>解析時(shí)會(huì)把我指定的class文件當(dāng)作一個(gè)壓縮文件進(jìn)行解壓,產(chǎn)生異常,改成如下定義即可:
<path id="axis.classpath">
<fileset dir="${axis.home}/WebRoot/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>
<pathelement location="${axis.home}/WebRoot/WEB-INF/classes"/>
</path>
第二個(gè)fileset改成pathelement,當(dāng)<taskdef>解析時(shí)會(huì)把指定的location當(dāng)作一個(gè)路徑,不會(huì)報(bào)錯(cuò)。
對(duì)于開源的ant真是又愛又恨啊,可恨的是文檔太少了,如<path>,<taskdef>的說明等,惜墨如金啊。