在用eclipes開發web service的時候,經常會用到java2wsdl,wsdl2java等命令,axis在發布的時候提供了相應的ant task,并放到了axis-ant.jar中。
按照axis的ant相關文檔配置的時候,需要引入相應的ant task,我在做這個配置的時候遇到了些障礙,開始的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>
在執行ant的時候,總是報
java.util.zip.ZipException: error in opening zip file
的錯誤,百思不得其解,后來找到了錯誤的原因,原來出在
<path id="axis.classpath">...</path>
的定義上,因為這里包含
<fileset dir="${axis.home}/WebRoot/WEB-INF/classes">
<include name="**/*.class" />
</fileset>
部分,<taskdef>解析時會把我指定的class文件當作一個壓縮文件進行解壓,產生異常,改成如下定義即可:
<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>
第二個fileset改成pathelement,當<taskdef>解析時會把指定的location當作一個路徑,不會報錯。
對于開源的ant真是又愛又恨啊,可恨的是文檔太少了,如<path>,<taskdef>的說明等,惜墨如金啊。