How to pass value to maven pom.xml at rum time fro

2019-01-20 18:57发布

问题:

I have a java file where a variable taken value at run time.I search for a service using web service discovery and keep its url in a variable. Now I need to pass this value to pom.xml.

abc.java has code with

String url= http://xx.xx.xx.xx:55939/ABCDevice?wsdl

Pom.xml is:

<wsdlOptions>
           <wsdlOption>
           <wsdl>url</wsdl> <!-- get urlvalue from java file -->
            <wsdlLocation>classpath:com/admin/discovery/ABCService.wsdl
                </wsdlLocation>
            </wsdlOption>
            </wsdlOptions>

In wsdl i want to pass string value "http://xx.xx.xx.xx:55939/ABCDevice?wsdl" which is determined only after run time.

How can i do so ?

回答1:

I don't consider this as an Apache Maven specific issue, but a general Java issue (Maven probably made you aware of it). During build-time you have no idea what the url should be. Depending on the type of application you have several options:

  • JNDI (in case of a webcontainer)
  • A properties file on a predefined location
  • System properties
  • As arguments (in case of executable jar)
  • Adjust web.xml before deploying (some webcontainers can help you with this)
  • ...

In you use a framework like Spring there are easy ways to inject one the options above.