How to distinguish between different wsdl locations in one pom.xml - Maven

守給你的承諾、 提交于 2019-12-24 16:26:21

问题


Is there a possibility to distinguish between multiple configurations of wsdl webservices in maven?

I have one application which can run on test, stage and prod environments. And I have to use one webservice. The webservice has 3 different wsdl locations. For test, stage and prod.

Is there a way in maven to say if I want to build my application for prod just use the webservice location for prod. And the same also for stage and test?

I have a wsdl import configuration which works fine for a single non-dynamical part.

<plugin>
 <groupId>org.jvnet.jax-ws-commons</groupId>
 <artifactId>jaxws-maven-plugin</artifactId>
 <version>2.3</version>
 <executions>
     <execution>
         <goals>
             <goal>wsimport</goal>
         </goals>
         <configuration>
             <wsdlFiles>
                 <wsdlFile>wsdlFile_live.wsdl</wsdlFile>
             </wsdlFiles>
             <vmArgs>
                 <vmArg>-Djavax.xml.accessExternalDTD=all</vmArg>
                 <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
             </vmArgs>
             <packageName>com.example.schema</packageName>
             <wsdlLocation>http://liveLocation/?wsdl</wsdlLocation>

         </configuration>
         <id>wsimport-generate-_live.wsdl</id>
         <phase>generate-sources</phase>
     </execution>
 </executions>
 <dependencies>
     <dependency>
         <groupId>javax.xml</groupId>
         <artifactId>webservices-api</artifactId>
         <version>2.0.1</version>
     </dependency>
 </dependencies>
 <configuration>
     <sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>
     <xnocompile>true</xnocompile>
     <verbose>true</verbose>
     <extension>true</extension>
     <catalog>${basedir}/src/jax-ws-catalog.xml</catalog>
 </configuration>


回答1:


Creating profiles in maven is one possibility to build different applications with different scopes.

<profiles>
    <profile>
        <id>prod</id>
        <build>
         ....
       </build>
    </profile>
    <profile>
        <id>test</id>
        <build>
            ....
       </build>
    </profile>  
</profiles>

In the profile property you can set dependencies, resourves, plugins, configurations and so on.

To build a specific profile you have to type mvn -P followed by the profile ID

In my case it looks like this: mvn -Ptest clean install or mvn -Pprod clean install




回答2:


You can use environment variables to store your wsdl file and pass to maven system properties. For example, say on Linux you want to access environment variable MY_VARIABLE. You can use a system property in your pom file.

<properties>
...
<!-- Default value for my.variable can be defined here -->
<my.variable>foo</my.variable>
...

... ${my.variable}

Set the property value on the maven command line:

mvn clean package -Dmy.variable=$MY_VARIABLE



来源:https://stackoverflow.com/questions/34796027/how-to-distinguish-between-different-wsdl-locations-in-one-pom-xml-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!