Search This Blog

Total Pageviews

Where to set the system properties in tomcat server.  Define

You can set the system parameters by specifying -D option (-Dcom.name.prop=value)

According to the Tomcat 6 docs, you'd have to write code like to use:

Context inictx = new InitialContext();
Context envCtx = (Context) inictx.lookup("java:comp/env");

// Look up our data source
String s = (String)envCtx.lookup("SMTP_PASSWORD");

 ServletContextListener set the System properties:
import java.util.Enumeration;
import javax.servlet.*;

public class SystemPropertiesHelper implements
        javax.servlet.ServletContextListener {
    private ServletContext context = null;

    public void contextInitialized(ServletContextEvent event) {
        context = event.getServletContext();
        Enumeration params = context.getInitParameterNames();

        while (params.hasMoreElements()) {
          String param = (String) params.nextElement();
          String value = 
          if (param.startsWith("customPrefix.")) {
              System.setProperty(param, value);

    public void contextDestroyed(ServletContextEvent event) {
And then put this into your web.xml (should be possible for context.xml too)



No comments:

java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport

SpringBoot Error: java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.j...