Search code examples
javatomcatcatalina

Getting tomcat's installation directory using java


I want to get tomcat's installation directory in my computer using java. I tried using :

System.getProperty("catalina.base");

and

System.getProperty("catalina.home");

But both methods return null as the answer. I tried it with System.getProperty("java.home"); and it correctly returns the java path. Any ideas as to what the problem is? Thanks


Solution

  • Try installing this JSP and passing various values for the "property" parameter:

    <%
      String propertyName = request.getParameter("property");
      Object propertyValue;
      String typeString;
      if(null == propertyName)
        propertyValue = null;
      else
        propertyValue = System.getProperty(propertyName);
    
      if(null == propertyValue)
        typeString = "null";
      else
        typeString = propertyValue.getClass().getName();
    %>
    The system property <code><%= propertyName %></code> has the value:
    <code><%= propertyValue %></code> (<%= typeString %>).
    

    Maybe you can find a pattern to which property values return null.