Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a System.getProperty() for an application running on Tomcat

Tags:

java

tomcat

I am trying to set a system property and retrieve it in my Servlet.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println(System.getProperty("name"));
    }

I placed this: -Dname=rickesh in CATALINA_OPTS but running the code returns null. I have no idea as to how I can pass parameters to Tomcat at runtime and use it via System.getProperty(String). A Google Search to do the same suggests to do a JNDI or set in CATALINA_OPTS, but no example on how to set either.

Please advice.

like image 699
Mono Jamoon Avatar asked Jan 02 '26 08:01

Mono Jamoon


1 Answers

After some hit and trial, placed name=rickesh in catalina.properties present in C:\apache-tomcat-6.0.35\conf. Works fine.

like image 78
Mono Jamoon Avatar answered Jan 03 '26 20:01

Mono Jamoon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!