Reputation: 137
i am trying to get the tomcat webapps folder based on environment where i deployed i tried the bellow code
String path= ctx.getRealPath("/");
op:C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps\myapp
this is giving upto root of the application i want to get the path upto webapps with out using any string removal on "path"
are there any other methods in context can provide me the tomcat webapps path ? anyone can help me one this?
Upvotes: 2
Views: 9115
Reputation: 2935
When tomcat starts up it registers a system property called catalina.base
you can do something like this
String tomcatBase = System.getProperty("catalina.base");
This will return (for your example) C:\Program Files\Apache Software Foundation\Tomcat 8.0
Then from there for a standard installation you can get to your webapp by doing
String webApp = String.format("%s/webapps/myapp", tomcatBase);
Then regardless of where you deploy tomcat, the path will always work.
Upvotes: 6