How to get the Tomcat home directory in Java

Q : Is there a function in Java to retrieve the Tomcat (Catalina) home directory?

A : Yes, Tomcat home directory or Catalina directory is stored at the Java System Property environment. If the Java web application is deployed into Tomcat web server, we can get the Tomcat directory with the following command


System.getProperty("catalina.base");

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
7 Comment threads
5 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
11 Comment authors
HareeshRAvishdudeKonstantin SvichkarVinit Bhardwaj Recent comment authors
newest oldest most voted
RAvish
Guest
RAvish

How to get the server home directory in Java, lets say i want to read property file located in wildfly-10.1.0.Finalstandaloneconfiguration path.

I am looking for general solution which is applicable for all servers.

Konstantin Svichkar
Guest
Konstantin Svichkar

how to specify ‘CATALINA_HOME’ path in log4j2.xml confiig file to store my logs in ?

Hareesh
Guest
Hareesh

${sys:catalina.home}/logs

Fernando Hellmann
Guest
Fernando Hellmann

I love u

ferng
Guest
ferng

maybe with an older version of tomcat, but not with v7.*.*

none_
Guest
none_

Why do you think? It’s working for me on Tomcat 7.

Anbazhagan
Guest
Anbazhagan

Hi

I am using this line System.getProperty(“catalina.base”); in coding but i through null value. Is any way to get the tomcat path thruough java?

Anbazhagan
Guest
Anbazhagan

I am using this line System.getProperty(“catalina.base”); in coding but it through null value. Is any way to get the tomcat path thruough java? I am using linux. I have installed tomcat in root.

Prateek Ashtikar
Guest
Prateek Ashtikar

Hi, System.getProperty(“catalina.base”); This line of code is also not giving correct values. Could anyone please suggest what is the problem?

dude
Guest
dude

System.getProperty(“catalina.home”)

anjan bacchu
Guest
anjan bacchu

hi there,

thanks for this info. I needed this for my work.

BR,
~A

Vinit Bhardwaj
Guest
Vinit Bhardwaj

You may use it.
String path =System.getenv(“CATALINA_HOME”);