我使用jaxws-maven-plugin为web服务使用者应用程序执行wsimport。我在wsimport上使用了-clientjar选项,它是在2010年JAX-WS2.2.2RI中引入的。我这样做是因为我想将WSDL捆绑在jar中。
我没有问题来制作这个波姆。对于插件配置,我执行如下操作:
<configuration>
...
<args>
<arg>-clientjar</arg>
<arg>bundled-wsdl.jar</arg>
</args>
</configuration>当我执行我创建的jar构建时,让我们称它为myapp.jar,其中包含文件bundled-wsdl.jar。在bundled-wsdl.jar的META目录中,我发现wsdl和xsd就像我喜欢的那样,我也很高兴使用-clientjar选项生成的java代码。
但是这些东西应该在myapp.jar的META中,对吧?它位于bundled-wsdl.jar的META中,这对我没有多大帮助。
有趣的是,我实际上在myapp.jar的META中获得了一个wsdl文件,这使得应用程序实际工作。我不知道它是如何到达的。而且,xsd文件不存在,只有在bundled-wsdl.jar的META中。
基本问题是如何在Maven项目中正确使用wsimport -clientjar选项?
Java 1.7.0_45。
发布于 2014-07-01 14:29:29
IMHO,-clientjar选项的文档确实很贫乏。我相信它的工作原理如下:
当使用-clientjar <jarfile>选项时,发生了三个事件:
<jarfile>工具的-d参数指向的目录中生成一个wsimport。这将同时包含WSDL和任何相关的XSD文件。这个小包袱根本不会被用来做任何事。如果你想利用它,这将完全取决于你。但在你看到下面(2)之前。除了作为文档的一种形式之外,我不知道如何使用这个jarfile。META-INF/wsdl/<svcname>.wsdl的文件中。生成的类将在no代理构造函数中使用该文件。因此,如果您使用-clientjar选项请求一个捆绑的WSDL文件,那么这就是实际使用的内容。@WebServiceClient类上使用默认的no-arg构造函数,那么@WebServiceClient将是捆绑的WSDL (来自(2)),而不是远程WSDL。实际上,如果您在命令行中与-wsdllocation一起使用-clientjar,那么您用-wsdllocation指定的任何内容都不会产生任何效果,因为-clientjar优先。所以我们必须把重点放在(2)和(3)上,因为这是唯一实际使用的.至少如果您按原样使用生成的代码。
值得注意的是,(2)的结果只是一个WSDL文件。这个文件可能包含到XSD文件的链接,但据我所知,这种链接将永远不会被遵循。原因是,当我们说web服务使用者在运行时需要WSDL时,它实际上只需要WSDL本身,而不是模式。模式被“硬编码”到使用者中,无法在运行时对其进行更改。因此,没有理由在运行时读取模式信息。(这是我的理解)
关于(2)中包含的WSDL,要注意的第二件事是:它实际上只是原始WSDL的一个副本,因此它可能没有您想要的端点。实际上,在大多数情况下,它不会。这意味着在这种情况下,您需要自己设置端点:
// Use no-arg constructor. Means it uses the WSDL bundled into the
// META-INF/wsdl directory rather than trying to retrieve WSDL over the
// network.
service = new HelloSvc_Service();
hello = service.getHelloSvcPort();
// Since we're using a bundled WSDL the web service URL cannot
// be derived from that (it would be wrong!). So we have to set
// it explicitly.
((BindingProvider) hello).getRequestContext().put(
BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
"http://myhellowebservice-address");发布于 2016-04-12 08:17:32
这个插件的文档是个笑话。解决方法是在创建客户端jar之后手动提取内容,如下所示:
<build>
<plugins>
<plugin>
<!--
Generates JAXWS classes for all of the WSDL files in $[project.base.dir}/src/wsdl.
-->
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<args>
<arg>-clientjar</arg>
<arg>${project.build.directory}/wsimport-client.jar</arg>
</args>
<wsdlUrls>
<wsdlUrl>https://webservice.com/service.wsdl</wsdlUrl>
</wsdlUrls>
</configuration>
</execution>
</executions>
<configuration>
<target>2.1</target>
<verbose>true</verbose>
</configuration>
</plugin>
<plugin>
<!--
Unjar the wsimport-client.jar created in the jaxws-maven-plugin to the WAR's classes folder
-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<target>
<unzip src="${project.build.directory}/wsimport-client.jar" dest="${project.build.directory}/classes" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>发布于 2021-10-22 16:48:26
我也遇到了同样的问题,我不得不将创建的jar解压缩并重新压缩到一个jar中(因此,将wsdl文件从内部jar放到最后一个jar中)。感谢peterh的评论,我想我理解了“诀窍”:在Maven输出中,我可以看到类似的日志
jaxws:wsimport args: [...,-Xnocompile, -clientjar wsdl.jar, ...]
因此,wsimport命令是在没有编译che代码的情况下启动的,实际上,wsdl.jar是在target/classes文件夹中创建的。我认为wsimport只是用wsdl生成源和jar,然后按照以下步骤编译和打包。
https://stackoverflow.com/questions/21115342
复制相似问题