从多个 wsdls 获取 java 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18595254/
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
Getting java classes from multiple wsdls
提问by Lokesh
I have a Maven project where i need to generate java classes from multiple wsdl files.
I have analysed using maven plugins axistools-maven-plugin
and cxf-codegen-plugin
but the problem i am facing are is that Java files from different wsdl's should go to different packages.
我有一个 Maven 项目,我需要从多个 wsdl 文件生成 java 类。我已经使用 maven 插件进行了分析axistools-maven-plugin
,cxf-codegen-plugin
但我面临的问题是来自不同 wsdl 的 Java 文件应该转到不同的包。
I have checked this link : http://decimalsolutions.blogspot.in/2011/10/wsdl2java-maven2.htmlbut it doesn't solve my problem.
我检查了这个链接:http: //decimalsolutions.blogspot.in/2011/10/wsdl2java-maven2.html但它没有解决我的问题。
How to achieve this?
如何实现这一目标?
采纳答案by JustDanyul
The documentationstates you can use the <extraarg>
element to pass in parameters to the wdsl to java process. So, you can configure your cxf-codegen-plugin
in the following manner
该文件指出,你可以使用<extraarg>
元素的参数传递给WDSL到java程序。因此,您可以cxf-codegen-plugin
通过以下方式配置您的
<configuration>
<sourceRoot>${project.build.directory}/generated-code/mywebservice</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/serviceOne.wsdl</wsdl>
<extraargs>
<extraarg>-p</extraarg>
<extraarg>first.packagename</extraarg>
</extraargs>
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/serviceTwo.wsdl</wsdl>
<extraargs>
<extraarg>-p</extraarg>
<extraarg>another.packagename</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
回答by MystyxMac
With a jaxb binding file, you can change the package (see thisdocumentation).
使用 jaxb 绑定文件,您可以更改包(请参阅此文档)。
If you're using maven and the cxf plugin, you can add this to your pom.xml:
如果你使用 maven 和 cxf 插件,你可以将它添加到你的 pom.xml 中:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl><path_to_wsdl</wsdl>
<frontEnd>jaxws21</frontEnd>
<faultSerialVersionUID>1</faultSerialVersionUID>
<bindingFiles>
<bindingFile>src/main/resources/binding.xml</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-fluent-api</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</dependency>
</dependencies>
</plugin>
回答by JohnMark13
Have you looked at XJC bindings, there are some notes on the Oracle siteand if you are happy with the CXF plugin you can pass a separate bindings file for each WSDL using the code you can see in example one on the plugin's site.
您是否查看过 XJC 绑定,Oracle 站点上有一些注释,如果您对 CXF 插件感到满意,您可以使用您在插件站点上的示例一中看到的代码为每个 WSDL 传递一个单独的绑定文件。
An example fragment from the plugin configuration:
插件配置中的示例片段:
...
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/first.wsdl</wsdl>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/first.xjb</bindingFile>
</bindingFiles>
</wsdlOption>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/second.wsdl</wsdl>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/second.xjb</bindingFile>
</bindingFiles>
</wsdlOption>
</wsdlOptions>
</configuration>
...
Where first.xjb would contain:
其中 first.xjb 将包含:
<jaxws:bindings wsdlLocation="path/to//serviceOne.wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<jaxws:bindings node="wsdl:definitions/wsdl:types/xs:schema">
<jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
...
</jxb:globalBindings>
<jxb:schemaBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
<jxb:package name="your.first.package"/>
</jxb:schemaBindings>
</jaxws:bindings>
</jaxws:bindings>
Now you can configure all manner of translations and mappings.
现在您可以配置所有方式的翻译和映射。