Referencing Environment Variables in web.xml

前端 未结 7 1281
無奈伤痛
無奈伤痛 2020-11-30 01:37

I\'m pre-packaging a JSP web-app that relies on some file path settings found within web.xml. These settings are unknown at packaging time, because they reference a path the

7条回答
  •  孤街浪徒
    2020-11-30 02:19

    You can use Ant-style variable substitution in any of the tomcat xml config files, such as:

    
        mvc-dispatcher
        ${foo}
    
    

    Where foo is a Java System Property (sysprop).

    You can't use OS Environment Variables (envvars) directly, I think...

    To use envvars, you can put

    set "CATALINA_OPTS=-DsomeJavaSysProp=%SOME_OS_ENVVAR%"
    

    in bin/setenv.bat (or similarly in bin/setenv.sh for *nix). You may need to create that file. Tomcat will run this file when it starts.

    As CATALINA_OPTS is an envvar (as opposed to a command line option), it should not be visible by other users on the system (save ancient Unixes), though I haven't tested this.

    http://tomcat.apache.org/tomcat-7.0-doc/config/

    If you are using Spring, you can create a bean and then directly use envvars or sysprops in Spring XML config files (though not web.xml).

提交回复
热议问题