如何解决在不同文件夹下生成的相同 类 与两个 WSDL 文件中给出的相同包 xmlns 之间的冲突?

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?

我有 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 标签中所述] 但使用相同的包即 [org.wso2.carbon.um.ws.service.ObjectFactory] 由于编译器抱怨类型 ObjectFactory 已定义且未生成 JAR 文件。

也试过给予

    <compilerArgument>-proc:none</compilerArgument>

没用。

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

提前致谢。

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

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

<?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

类似的 Whosebug 问题:

Customizing Java packages JAXB wsimport

How to generate classes from wsdl using Maven and wsimport?