Search code examples
javatomcatservletsconfigurationjvm-arguments

Tomcat Replacing VM arguments


this may be a stupid question:

I currently have some VM arguments that my web application requires. They are something like:

-Dcom.company.custom.var='test'

And I access them in code with:

System.getProperty("com.company.custom.config")

I would like to move them into one of the tomcat xml files (server.xml, context.xml, etc) but I'm not sure how I would go about doing that.

So my question is two parts. Where (and how) should I put these variables into xml and how do I access them in code?

Thanks in advance and sorry if this has already been answered. My search-fu on this topic has failed me.


Solution

  • Officially, all JVM options go either to setenv.sh (for Unix) or setenv.bat (for Windows). This file is not present by default in Tomcat but if you create one, it will be picked up by startup script.

    The reason why you should be using this instead of server.xml is that server.xml might change from one Tomcat version to another but setenv.sh (or .bat) is completely custom to you.

    Reading this value is, as you pointed out, through System.getProperty(...).