【问题标题】:Externally configuring a WSDL location in the maven-jaxb2-plugin在 maven-jaxb2-plugin 中外部配置 WSDL 位置
【发布时间】:2017-06-22 14:46:05
【问题描述】:

我正在尝试在我的 Java 应用程序中调用外部 SOAP 服务。为此,我想从某个域上公开的 wsdl 生成请求和响应对象。我正在使用 maven-jaxb2-plugin 来执行此操作:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.13.1</version>
        <executions>
            <execution>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
    <configuration>
        <schemaLanguage>WSDL</schemaLanguage>
        <generatePackage>example.wsdl</generatePackage>
        <schemas>
            <schema>
                <url>http://someaddress/example.wsdl</url>
            </schema>
        </schemas>
    </configuration>
</plugin>

问题是:我希望能够根据应用程序将要部署到的环境更改 WSDL 的 URL (http://someaddress/example.wsdl)。我正在考虑使用系统属性来做到这一点,但有没有更好的做法来实现这一点?

编辑:经过更多搜索,我发现了一个类似的问题,但在 C# 上下文中。这可能有助于提出解决方案吗? How can you use two WSDLs and maintain a test instance with a C# application?

【问题讨论】:

    标签: java maven wsdl jaxb2


    【解决方案1】:

    使用Maven profiles

    以下配置示例:

    <!-- Profile configuration -->
    <profiles>
        <!-- The configuration of the development profile -->
        <profile>
            <id>dev</id>
            <!-- The development profile is active by default -->
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
              <build.profile.url>http://someaddress/example.wsdl</build.profile.url>
            </properties>
        </profile>
        <!-- The configuration of the production profile -->
        <profile>
            <id>prod</id>
            <properties>
             <build.profile.url>http://someaddress/example2.wsdl</build.profile.url>
            </properties>
        </profile>
        <!-- The configuration of the testing profile -->
        <profile>
            <id>test</id>
            <properties>
               <build.profile.url>http://someaddress/example3.wsdl</build.profile.url>
            </properties>
        </profile>
    </profiles>
    

    然后在你的插件中

    <schemas>
            <schema>
                <url>${build.profile.url}</url>
            </schema>
        </schemas>
    

    要使用配置文件dev 安装工件

    mvn clean install -P dev
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      相关资源
      最近更新 更多