Using variables in pom.xml

前端 未结 1 1658
猫巷女王i
猫巷女王i 2021-01-13 19:46

I want to use a variable which has different values in the properties file depending on the environment. I want to use that variable in my pom.xml.

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-13 20:27

    You are looking for Maven Resource Filtering

    There are 3 steps to follow when using resource filtering:

    Step 1:

    Add a set of appropriate entries in your pom and include the variables you need in a list of :

    
        Dev
        
            dev.proxy.host
            1234
        
    
    
        QA
        
            QA.PROXY.NET
            8888
        
    
    
        Prod
        
            true
        
        
            PROD.PROXY.NET
            8080
        
    
    

    Notice that the Prod profile has been tagged: .

    Step 2:

    Within the properties file, use pom-style variable demarcation to add variable value placeholders, matching the tag names used in the pom:

    proxyServer=${proxyServer}
    proxyPort=${proxyPort}
    

    Step 3:

    Within the pom's section, add a entry (assuming that your properties are in the src/main/resources directory), include a tag, and set the value to: true:

    
        
            src/main/resources
            true
            
                settings.properties
            
        
    
    

    Then, when you run your Maven build, the demarcated property values will be replaced with the values that are defined in the pom entries.

    0 讨论(0)
提交回复
热议问题