How do I add a .properties file into my WAR using gradle?

前端 未结 4 465
再見小時候
再見小時候 2020-12-10 10:28
WAR
   - META-INF
   - WEB-INF
       - classes
           - META-INF
               - myApp.properties <-- Needs added

How do I add a .properti

相关标签:
4条回答
  • 2020-12-10 10:59
    war {
        from('<path-to-props-file>') {
            include 'myApp.properties'
            into('<target-path>')
        }
    }
    
    0 讨论(0)
  • 2020-12-10 11:01

    eg1:

    war {
        webInf{
            from('PATH_TO_SOURCE_FOLDER') {
                include 'FILE_TO_BE_INCLUDED'
                into('TARGET_FOLDER_RELATIVE_TO_WEB_INF_DIR')
            }
        }
    }
    

    eg2:

    war {
        webInf{
            from('src/META-INF') {
                include 'persistence.xml'
                into('classes/META-INF/')
            }
        }
    }
    

    For more information check the online documentation: Chapter 26. The War Plugin

    0 讨论(0)
  • 2020-12-10 11:13

    Something like this should work:

    war {
        from('<path-to-props-file>') {
            include 'myApp.properties'
        }
    }
    

    If you want to specify which directory you want the properties file to be located in:

    war { 
        from('<path-to-props-file>') { 
            include 'myApp.properties' 
            into('<targetDir>') 
        }
    } 
    
    0 讨论(0)
  • 2020-12-10 11:23

    I normally use an environments folder from which I pick a given configuration file based on the deploy variable. Ex.:

    from("environments/system.${env}.properties"){
            include "system.${env}.properties"
            into 'WEB-INF'
            rename("system.${env}.properties", 'system.properties')
    }
    

    the property is passed through gradle as:

    ./gradlew buildDocker  -Penv=prod
    
    0 讨论(0)
提交回复
热议问题