java WsImport ant 任务和 JDK 6
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6862345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WsImport ant task and JDK 6
提问by Travis
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:
我正在尝试使用 jax-ws 生成 web 服务代理类,使用 wsimport ant 任务,类似于这个问题,有以下后续问题:
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.
据我了解,较新的 JDK 1.6 版本包括 jax-ws 并且 WsImport ant 任务在 JDK 的 tools.jar 文件中定义。
Why does ant not find this automatically?
为什么蚂蚁不会自动找到这个?
Why does eclipse not find this automatically as well?
为什么 Eclipse 也不会自动找到它?
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).
我发现了一些在 JDK 6 中使用 jax-ws 的参考,但这些似乎是基于复制单独下载的 jax-ws 库并将其放入 JDK ext 文件夹(我认为不再需要,因为它实际上是现在与 JDK 捆绑在一起)。
What is the proper way to use the wsimport task with a version of JDK 1.6 that already includes jax-ws?
在已经包含 jax-ws 的 JDK 1.6 版本中使用 wsimport 任务的正确方法是什么?
My build XML:
我的构建 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>
回答by Travis
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.
事实证明,JDK 中的 WsImport 类实际上并不是一个 ant 任务,而是实际的 wsimport 命令行工具。我也误读了包名: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.
实际的 ant 任务可在此处Metro 包中的 webservices-tools.jar 中找到。您需要将其放到 ant lib 目录中。
回答by pcesarperez
As far as I know, what is bundled with the JDK6 is the binary toolitself, not the actual Ant task.
据我所知,JDK6 捆绑的是二进制工具本身,而不是实际的 Ant 任务。
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.
我的开发箱中有 Java 1.6.0_31,虽然有点特殊(JRockit R28.2.3),这是我发现wsimport
正确使用任务的唯一方法。
- 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.
- 从官方站点下载合适版本的 JAX-WS。对于 JDK6,它的版本应该是2.1.10。如果您尝试使用 2.2+ 版本,则会遇到类路径冲突。
- 使用 安装 JAR 内容
java -jar {jaxwsJarName}
,无论它是什么名称。此命令将创建一个[jaxws-ri]
文件夹。 [jaxws-ri/lib]
在选择的位置复制文件夹的内容。尽管规模很大,但我喜欢在我自己的项目中使用外部库,以确保任何人都可以在没有外部工件的情况下编译和打包代码。- 在构建文件中创建
taskdef
项目和wsimport
任务。
This is my taskdef
item:
这是我的taskdef
项目:
<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:
这是我的wsimport
任务:
<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>