Load Properties from a file into SystemProperties or as an Attribute in ServletContext, using WebappBaseName as reference in a servlet container like Tomcat. Open Source Java project under Apache License v2.0
Current Stable Version is 1.0.0
- Place
webapp-properties-x.x.x.jar
intomcat/lib/
<!-- Context Listener for Servlet Container -->
<!-- tomcat/conf/web.xml or WEB-INF/web.xml -->
<listener>
<description>Load Properties from a file into SystemProperties or as an Attribute in ServletContext, using WebappBaseName as reference</description>
<listener-class>org.javastack.webappproperties.WebAppPropertiesContextListener</listener-class>
</listener>
Note: If you have more than one webapp per JVM and you are loading this to system-properties without SystemClassLoaderProperties the keys with same name can collide and view unexpected values. Properties as Attribute in ServletContext may be better alternative than Global System Properties.
- Default system properties (never overwrite existing property):
{baseDir}/appconf/{webappBaseName}/system-properties-default.properties
- Forced system properties (always overwrite existing property):
{baseDir}/appconf/{webappBaseName}/system-properties-forced.properties
- Context Attribute properties:
{baseDir}/appconf/{webappBaseName}/context.properties
{webappBaseName}
follow the Tomcat Basenames convention
- org.javastack.webappproperties.conf
- catalina.base
- catalina.home
- user.dir
final String CONST_CONTEXT_ATTRIBUTE_NAME = "org.javastack.webappproperties.ctx";
final Properties p = (Properties) getServletContext().getAttribute(CONST_CONTEXT_ATTRIBUTE_NAME);
<dependency>
<groupId>org.javastack</groupId>
<artifactId>webapp-properties</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
Inspired in SystemClassLoaderProperties and CatalinaProperties, this code is Java-minimalistic version.