java—如何解决在不同文件夹下生成的相同类之间的冲突,但使用两个wsdl文件中给定的相同包xmlns?

368yc8dk  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(367)

我有两个wsdl,即userstore.wsdl和authorization.wsdlxmlns: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类是在不同的文件夹xjc和jaxws wsimport wsdl下生成的[如sourcedestdir标记中所述],但是使用相同的包,即[org.wso2.carbon.um.ws.service.objectfactory],由于该包,编译器抱怨类型objectfactory已经定义,而jar文件没有得到生成。
也试过给予

<compilerArgument>-proc:none</compilerArgument>

但没用。
我们不允许修改wsdl,需要解决这个问题。
提前谢谢。

wkyowqbh

wkyowqbh1#

所以我对你的问题的理解是你想要定义不同的包?
要使用绑定文件配置目标包,请执行以下操作:

<?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-绑定文件中的目标包
你也可以使用

<packageName>
The package in which the source files will be generated.

    Type: java.lang.String
    Required: No

类似问题:
定制java包jaxb wsimport
如何使用maven和wsimport从wsdl生成类?

相关问题