使用maven从多个Web服务生成类

时间:2018-03-23 17:50:58

标签: maven spring-boot wsdl

我有一个POM,我使用JAXB2插件从多个webservices(wsdl)生成代码。

<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    <!-- maven-jaxb2-plugin -->
    <plugin>
        <groupId>org.jvnet.jaxb2.maven2</groupId>
        <artifactId>maven-jaxb2-plugin</artifactId>
        <executions>
            <execution>
            <id>Bus</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <schemas>
                        <schema>
                            <url>http://server/Service1?wsdl</url>
                        </schema>
                    </schemas>
                    <generatePackage>com.core.business</generatePackage>
                </configuration>
            </execution>
            <execution>
            <id>Ser</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <schemas>
                        <schema>
                            <url>http://server/Service2?wsdl</url>
                        </schema>
                    </schemas>
                    <generatePackage>com.core.search</generatePackage>
                </configuration>
            </execution>
            <execution>
            <id>Tab</id>                    
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <schemas>
                        <schema>
                            <url>http://server/Service3?wsdl</url>
                        </schema>
                    </schemas>
                    <generatePackage>com.core.table</generatePackage>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

生成的类文件都包含在所有Packages中。因此

  • com.core.business
  • com.core.search
  • com.core.table

由于wsdl1,2,3的类组合在所有3个包中,似乎没有正确处理命名空间。

如何确保这些包包含wsdl中指定的特定类?

1 个答案:

答案 0 :(得分:1)

<url><generatePackage>属性两侧的星号是外卡字符。

请参阅http://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.2/example_xjc_basic.html

中的此示例
<project>
...
<dependencies>
    <!--
        You need the JAXB API to be able to annotate your classes.
        However, starting with Java 6 that API is included in the
        Java SE platform so there is no need to declare a dependency.
    -->
    ...
</dependencies>
...
<build>
    <pluginManagement>
        <plugins>
            <!--
                If we e.g. execute on JDK 1.7, we should compile for Java 7 to get
                the same (or higher) JAXB API version as used during the xjc execution.
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>${project.version}</version>
            <executions>
                <execution>
                    <id>xjc</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- The package of your generated sources -->
                <packageName>com.example.myschema</packageName>
            </configuration>
        </plugin>
        ...
    </plugins>
<build>
...
</project>

我肯定会接受这些行开头的***。我可以通过https://github.com/highsource/maven-jaxb2-plugin/wiki/Configuration-Cheat-Sheet

快速找到问题的答案