WsImport ant task and JDK 6
I am trying to use jax-ws to generate web service proxy classes, using the wsimport ant task, similarly to this question, with the following follow-on question:
As I understand it, more recent versions of JDK 1.6 include jax-ws and the WsImport ant task is defined in the JDK's tools.jar file.
Why does ant not find this automatically?
Why does eclipse not find this automatically as well?
I found a few references to using jax-ws with JDK 6, but these seem to be based on copying a separately downloaded jax-ws library and dropping it into the JDK ext folder (which I assume is no longer required given that it is actually bundled with the JDK now).
What is the proper way to use the wsimport t开发者_Go百科ask with a version of JDK 1.6 that already includes jax-ws?
My build XML:
<?xml version="1.0" encoding="UTF-8"?>
<project name="wsproxy">
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport" />
<target name="wsgentest">
<wsimport
wsdl="http://localhost/Service?wsdl"
destdir="bin-gen"
sourcedestdir="src-gen"
keep="true"
verbose="true"
package="com.ws">
</wsimport>
</target>
</project>
It turns out the WsImport class that is in the JDK is not actually an ant task, but the actual wsimport command line tool. I misread the package name as well: com.sun.tools.internal.ws.
The actual ant task is available in webservices-tools.jar in the metro package here. You will need to drop it in the ant lib directory.
As far as I know, what is bundled with the JDK6 is the binary tool itself, not the actual Ant task.
I have Java 1.6.0_31 in my dev box, although a slightly special one (JRockit R28.2.3), and this is the only way I have found to use wsimport
task properly.
- Download a suitable version of JAX-WS from the official site. With JDK6 it should be a version up to 2.1.10. If you try to use version 2.2+, you will have a classpath conflict.
- Install the JAR contents with
java -jar {jaxwsJarName}
, whatever name it is. This command will create a[jaxws-ri]
folder. - Copy the contents of
[jaxws-ri/lib]
folder in the location of choice. In spite of the size, I like to have the external libraries along my own projects, to ensure anyone may be able to compile and package the code with no external artifacts. - Create the
taskdef
item and thewsimport
task in your build file.
This is my taskdef
item:
<taskdef
name="wsimport"
classname="com.sun.tools.ws.ant.WsImport">
<classpath>
<fileset dir="${lib.dir}/jaxws-ri-2.1.10">
<include name="**/*.jar" />
</fileset>
</classpath>
</taskdef>
And this is my wsimport
task:
<target name="generate-code">
<wsimport
wsdl="${wsdl.dir}/${wsdl.name}-${wsdl.version}.wsdl"
sourcedestdir="${src.dir}"
destdir="${build.debug.dir}"
package="${generated.code.package}">
<depends file="${wsdl.dir}/${wsdl.name}-${wsdl.version}.wsdl" />
<produces dir="${build.debug.dir}" />
</wsimport>
</target>
精彩评论