java - 在 maven-jaxb2-plugin 中外部配置 WSDL 位置

标签 java maven wsdl jaxb2

我正在尝试在 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 ( http://someaddress/example.wsdl ) 的 URL。我正在考虑使用系统属性来执行此操作,但是是否有更好的实践来实现此目的?

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

最佳答案

使用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 安装 Artifact

mvn clean install -P dev

关于java - 在 maven-jaxb2-plugin 中外部配置 WSDL 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44702717/

相关文章:

maven - 如何使用 gpg 签名配置 Jenkins (Hudson)

java - 将 java 应用程序部署到 weblogic 时出错

java - 为什么axis2 1.6.2 java2wdsl.sh忽略复杂类型的类成员

java - 为什么我的格式这么奇怪?

java - 当程序抛出 IOException 时,如何修复 FileNotFoundException?

java - 为什么启动程序3次后才出现JTextfield和JButton?

java - 由 : org. hibernate.exception.JDBCConnectionException 引起:调用 Driver#connect 时出错

java - 为什么我无法让注入(inject)发挥作用?