Posts Tagged ‘System property’
WebLogic: set a System property within a WAR
Case
You would like to set a System property within an application packaged as a WAR.
Of course, you may modify the launching scripts of your servers, to add an option -DmyPropertyName=myPropertyValue
. Sometimes, you would like to avoid such a solution, because updating the property would require an update of the setEnv.*
files and therefore a action of the exploitation team.
In my case, I had to set the property tangosol.coherence.cacheconfig
, which hints at the configuration file used my Oracle Coherence / Coherence*Web
Fix
The first solution is to set the property in a startup class. For more detials, consult this page: WebLogic: use a startup and/or a shutdown class in a WAR.
Another mean to handle this problematic is to create a servlet, with a code similar to:
[java]public class JonathanBootServlet extends HttpServlet {
private static final Logger LOGGER = Logger.getLogger(JonathanBootServlet.class);
private static final String SVN_ID = "$Id$";
public JonathanBootServlet() {
super();
if (LOGGER.isDebugEnabled()){
LOGGER.debug(SVN_ID);
}
}
public void init(ServletConfig config) throws ServletException {
if (LOGGER.isDebugEnabled()){
LOGGER.debug("in init()");
}
System.setProperty("tangosol.coherence.cacheconfig", "jonathan-tangosol-coherence.xml");
super.init(config);
}
}[/java]
Then add the following block in your web.xml:
[xml] <servlet>
<servlet-name>JonathanBootServlet</servlet-name>
<servlet-class>lalou.jonathan.weblogic.technical.JonathanBootServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>[/xml]
Ensure this servlet is run before all others (1
).