如何通过wsgen生成wsdl作为ant任务
how to generate wsdl through wsgen as ant task
尝试通过 wsgen 作为 ANT 任务从 java 应用程序服务生成 jax-ws wsdl 文件。
Ant 的 taskdef 本身给了我很多 class not found 异常。
每次它给出 class not fount for "com.sun.tools.ws.ant.WsGen" 然后在 class 路径中添加 "jaxws-tools-2.1.7.jar"。在此之后,它给出 class not found for "com/sun/istack/tools/ProtectedTask" 然后添加 "istack-commons-tools-2.7.jar"。
现在它给出 class not found for "com/sun/tools/xjc/api/util/ToolsJarNotFoundException"
我确定,我走的路不对。
这里是build.xml
<?xml version="1.0"?>
<project name="Application Services" basedir="." default="compile">
<property file="build.properties"/>
<path id="external.projects">
<fileset dir="/scratch/softwares" includes="*.jar"/>
</path>
<taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen" classpathref="external.projects">
</taskdef>
<target name="compile" depends="clean,init">
<javac destdir="${build.dir}" srcdir="${src.dir}" classpathref="external.projects"/>
</target>
<target name="packaging" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/application.services.jar" basedir="${build.dir}"/>
<wsgen
sei="webservice.interfaces.student.IStudentApplicationService"
destdir="${jar.dir}" cp="external.projects" resourcedestdir="${jar.dir}"
sourcedestdir="${jar.dir}" genwsdl="true"
/>
</target>
</project>
调试 jar 之间的依赖关系会让你发疯......你的 ANT 项目需要的是一个依赖管理器,例如 Apache ivy.
我注意到的第二个问题是您 运行 一个非常旧的版本是 jaxws-tools,于 2009 年发布。从那以后就有了 lots and lots of updates。
例子
演示如何使用 ivy 为 wsgen 任务创建托管类路径。
<ivy:cachepath pathid="wsgen.path">
<dependency org="com.sun.xml.ws" name="jaxws-tools" rev="2.2.10" />
</ivy:cachepath>
<taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen" classpathref="wsgen.path"/>
build.xml
<?xml version="1.0"?>
<project name="Application Services" basedir="." default="packaging" xmlns:ivy="antlib:org.apache.ivy.ant">
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<target name="install-ivy" description="Install ivy" unless="ivy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
<target name="resolve" depends="install-ivy" description="Use ivy to resolve classpaths">
<ivy:cachepath pathid="wsgen.path">
<dependency org="com.sun.xml.ws" name="jaxws-tools" rev="2.2.10" />
</ivy:cachepath>
</target>
<target name="packaging" depends="resolve">
<taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen" classpathref="wsgen.path"/>
<wsgen
sei="webservice.interfaces.student.IStudentApplicationService"
destdir="${jar.dir}" cp="external.projects" resourcedestdir="${jar.dir}"
sourcedestdir="${jar.dir}" genwsdl="true"
/>
</target>
</project>
备注:
- 此构建文件将自动安装 ivy 插件
- 依赖项会自动下载并缓存在 "resolve" 目标中。
用常春藤完成build.xml...
<?xml version="1.0"?>
<project name="Application Services" basedir="." default="compile" xmlns:ivy="antlib:org.apache.ivy.ant">
<property file="build.properties"/>
<path id="external.projects">
<fileset dir="../xface.dto/${jar.dir}" includes="*.jar"/>
<fileset dir="../webservice.interfaces/${jar.dir}" includes="*.jar"/>
</path>
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<target name="info">
<echo>Apache Ant!</echo>
</target>
<target name="clean">
<echo>cleaning....</echo>
<delete dir="${build.dir}"/>
<delete dir="${jar.dir}"/>
</target>
<target name="init">
<echo>init....</echo>
<mkdir dir="${build.dir}"/>
</target>
<target name="compile" depends="clean,init">
<echo>compiling....</echo>
<javac destdir="${build.dir}" srcdir="${src.dir}" classpathref="external.projects"/>
</target>
<target name="install-ivy" unless="ivy.installed">
<echo>installing ivy....</echo>
<mkdire dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar" />
<fail message="Ivy has been installed. Run the build again"/>
</target>
<target name="resolve" depends="install-ivy">
<ivy:cachepath pathid="wsgen.path">
<dependency org="com.sun.xml.ws" name="jaxws-tools" rev="2.2.10" />
</ivy:cachepath>
</target>
<target name="packaging" depends="compile,resolve">
<taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen" classpathref="wsgen.path"/>
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/application.services.jar" basedir="${build.dir}"/>
<wsgen
sei="application.services.student.StudentApplicationService"
destdir="${jar.dir}" resourcedestdir="${jar.dir}"
sourcedestdir="${jar.dir}" genwsdl="true"
>
<classpath>
<fileset dir="../xface.dto/${jar.dir}" includes="*.jar"/>
<fileset dir="../webservice.interfaces/${jar.dir}" includes="*.jar"/>
<pathelement location="./bin"/>
</classpath>
</wsgen>
</target>
</project>
尝试通过 wsgen 作为 ANT 任务从 java 应用程序服务生成 jax-ws wsdl 文件。 Ant 的 taskdef 本身给了我很多 class not found 异常。 每次它给出 class not fount for "com.sun.tools.ws.ant.WsGen" 然后在 class 路径中添加 "jaxws-tools-2.1.7.jar"。在此之后,它给出 class not found for "com/sun/istack/tools/ProtectedTask" 然后添加 "istack-commons-tools-2.7.jar"。 现在它给出 class not found for "com/sun/tools/xjc/api/util/ToolsJarNotFoundException"
我确定,我走的路不对。
这里是build.xml
<?xml version="1.0"?>
<project name="Application Services" basedir="." default="compile">
<property file="build.properties"/>
<path id="external.projects">
<fileset dir="/scratch/softwares" includes="*.jar"/>
</path>
<taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen" classpathref="external.projects">
</taskdef>
<target name="compile" depends="clean,init">
<javac destdir="${build.dir}" srcdir="${src.dir}" classpathref="external.projects"/>
</target>
<target name="packaging" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/application.services.jar" basedir="${build.dir}"/>
<wsgen
sei="webservice.interfaces.student.IStudentApplicationService"
destdir="${jar.dir}" cp="external.projects" resourcedestdir="${jar.dir}"
sourcedestdir="${jar.dir}" genwsdl="true"
/>
</target>
</project>
调试 jar 之间的依赖关系会让你发疯......你的 ANT 项目需要的是一个依赖管理器,例如 Apache ivy.
我注意到的第二个问题是您 运行 一个非常旧的版本是 jaxws-tools,于 2009 年发布。从那以后就有了 lots and lots of updates。
例子
演示如何使用 ivy 为 wsgen 任务创建托管类路径。
<ivy:cachepath pathid="wsgen.path">
<dependency org="com.sun.xml.ws" name="jaxws-tools" rev="2.2.10" />
</ivy:cachepath>
<taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen" classpathref="wsgen.path"/>
build.xml
<?xml version="1.0"?>
<project name="Application Services" basedir="." default="packaging" xmlns:ivy="antlib:org.apache.ivy.ant">
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<target name="install-ivy" description="Install ivy" unless="ivy.installed">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
<target name="resolve" depends="install-ivy" description="Use ivy to resolve classpaths">
<ivy:cachepath pathid="wsgen.path">
<dependency org="com.sun.xml.ws" name="jaxws-tools" rev="2.2.10" />
</ivy:cachepath>
</target>
<target name="packaging" depends="resolve">
<taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen" classpathref="wsgen.path"/>
<wsgen
sei="webservice.interfaces.student.IStudentApplicationService"
destdir="${jar.dir}" cp="external.projects" resourcedestdir="${jar.dir}"
sourcedestdir="${jar.dir}" genwsdl="true"
/>
</target>
</project>
备注:
- 此构建文件将自动安装 ivy 插件
- 依赖项会自动下载并缓存在 "resolve" 目标中。
用常春藤完成build.xml...
<?xml version="1.0"?>
<project name="Application Services" basedir="." default="compile" xmlns:ivy="antlib:org.apache.ivy.ant">
<property file="build.properties"/>
<path id="external.projects">
<fileset dir="../xface.dto/${jar.dir}" includes="*.jar"/>
<fileset dir="../webservice.interfaces/${jar.dir}" includes="*.jar"/>
</path>
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<target name="info">
<echo>Apache Ant!</echo>
</target>
<target name="clean">
<echo>cleaning....</echo>
<delete dir="${build.dir}"/>
<delete dir="${jar.dir}"/>
</target>
<target name="init">
<echo>init....</echo>
<mkdir dir="${build.dir}"/>
</target>
<target name="compile" depends="clean,init">
<echo>compiling....</echo>
<javac destdir="${build.dir}" srcdir="${src.dir}" classpathref="external.projects"/>
</target>
<target name="install-ivy" unless="ivy.installed">
<echo>installing ivy....</echo>
<mkdire dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar" />
<fail message="Ivy has been installed. Run the build again"/>
</target>
<target name="resolve" depends="install-ivy">
<ivy:cachepath pathid="wsgen.path">
<dependency org="com.sun.xml.ws" name="jaxws-tools" rev="2.2.10" />
</ivy:cachepath>
</target>
<target name="packaging" depends="compile,resolve">
<taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen" classpathref="wsgen.path"/>
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/application.services.jar" basedir="${build.dir}"/>
<wsgen
sei="application.services.student.StudentApplicationService"
destdir="${jar.dir}" resourcedestdir="${jar.dir}"
sourcedestdir="${jar.dir}" genwsdl="true"
>
<classpath>
<fileset dir="../xface.dto/${jar.dir}" includes="*.jar"/>
<fileset dir="../webservice.interfaces/${jar.dir}" includes="*.jar"/>
<pathelement location="./bin"/>
</classpath>
</wsgen>
</target>
</project>