【问题标题】:How to solve the conflicts between the same classes getting generated under different folders but with the same package xmlns given in two WSDL files?如何解决在不同文件夹下生成的相同类之间的冲突,但在两个 WSDL 文件中给出了相同的包 xmlns?
【发布时间】:2020-12-11 12:10:05
【问题描述】:

我有 2 个 WSDL,即 UserStore.wsdl 和 Authorization.wsdl,xmlns:ns="http://service.ws.um.carbon.wso2.org"

            <plugin>
            <groupId>org.jvnet.jax-ws-commons</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>2.2.1</version>
            <executions>
             <execution>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <vmArgs>
                            <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                        </vmArgs>
                        <args>
                            <arg>-B-XautoNameResolution</arg>
                        </args>
                        <wsdlFiles>
                            <wsdlFile>RemoteAuthorizationManagerService.wsdl</wsdlFile>
                        </wsdlFiles>
                        <wsdlDirectory>${basedir}/src/main/wsdl</wsdlDirectory>
                        <staleFile>${project.build.directory}/jaxws/stale/RemoteAuthorizationManagerService.stale</staleFile>
                        <wsdlLocation>/META-INF/wsdl/RemoteAuthorizationManagerService.wsdl</wsdlLocation>
                    </configuration>
                    <id>wsimport-generate-RemoteAuthorizationManagerService</id>
                    <phase>generate-sources</phase>
                </execution>
                <execution>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <vmArgs>
                            <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                        </vmArgs>
                        <args>
                            <arg>-B-XautoNameResolution</arg>
                        </args>
                        <wsdlFiles>
                            <wsdlFile>RemoteUserStoreManagerService.wsdl</wsdlFile>
                        </wsdlFiles>
                        <wsdlDirectory>${basedir}/src/main/wsdl</wsdlDirectory>
                        <staleFile>${project.build.directory}/jaxws/stale/RemoteUserStoreManagerService.stale</staleFile>
                        <wsdlLocation>/META-INF/wsdl/RemoteUserStoreManagerService.wsdl</wsdlLocation>
                        <sourceDestDir>${project.build.directory}/generated-sources/xjc</sourceDestDir>
                        <compilerArgument>-proc:none</compilerArgument>
                    </configuration>
                    <id>wsimport-generate-RemoteUserStoreManagerService</id>
                    <phase>generate-sources</phase>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>javax.xml</groupId>
                    <artifactId>webservices-api</artifactId>
                    <version>1.4</version>
                </dependency>
            </dependencies>
            <configuration>
                <sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport-wsdl</sourceDestDir>
                <xnocompile>true</xnocompile>
                <verbose>true</verbose>
                <extension>true</extension>
                <keep>true</keep>
                <catalog>${basedir}/src/jax-ws-catalog.xml</catalog>
                <compilerArgument>-proc:none</compilerArgument>
            </configuration>
            </plugin>

我们面临的根本原因是 ObjectFactory 类在不同的文件夹 XJCjaxws-wsimport-wsdl [如 sourceDestDir 中所述strong> 标签] 但使用相同的包,即 [org.wso2.carbon.um.ws.service.ObjectFactory] 由于编译器抱怨 ObjectFactory 类型已定义且未生成 JAR 文件.

也尝试过给予

    <compilerArgument>-proc:none</compilerArgument>

这没用。

我们不允许修改 WSDL,需要解决这个问题。

提前致谢。

【问题讨论】:

    标签: java spring-boot web-services soap wsdl


    【解决方案1】:

    所以我对你的问题的理解是你想要定义不同的包?

    使用绑定文件配置目标包:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <jaxb:bindings
        version="2.1"
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:xs="http://www.w3.org/2001/XMLSchema">
    
        <jaxb:bindings schemaLocation="a.xsd" node="//xs:schema">
            <jaxb:schemaBindings>
                <jaxb:package name="org.ab.a"/>
            </jaxb:schemaBindings>
        </jaxb:bindings>
    </jaxb:bindings>
    

    https://github.com/highsource/maven-jaxb2-plugin/wiki/Configure-Target-Packages-in-Binding-Files#configure-target-packages-in-binding-files


    你也可以使用

    <packageName>
    The package in which the source files will be generated.
    
        Type: java.lang.String
        Required: No
    

    类似的 Stackoverflow 问题:

    Customizing Java packages JAXB wsimport

    How to generate classes from wsdl using Maven and wsimport?

    【讨论】:

    • 非常好的答案。非常感谢。它就是这样工作的。
    • 很高兴能帮上忙
    猜你喜欢
    • 2018-08-14
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多