Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String tomcatpath=System.getProperty("catalina.base") is not working in Eclipse ,but working in cmd  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Team ,

I have configured eclipse with Tomcat 7.I have configured my project and deployed in tomcat in eclipse.Currently I am facing one issue like

I have one java file .There is some code written like String tomcatpath=System.getProperty("catalina.base") to fetch the tomcat path and there in /shared folder ,/conf folder some properties files are there and they need to be read from that path.  .

At the time of starting tomcat in startup.batch in cmd prompt ,String tomcatpath=System.getProperty("catalina.base") is executed properly and properties file successfully read ,but while starting tomcat in eclipse  String tomcatpath=System.getProperty("catalina.base") is not reading properly.It is not fetching my tomcat home directory  (System.getProperty("catalina.base") ) .

Can anybody help me regarding on this ?
 
Bartender
Posts: 19217
85
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best help I can give you is to advise not to have your webapps attempt to locate where Tomcat is installed at all. There's really no good reason - although a lot of really bad reasons - why webapps should not be poking around in Tomcat's directories. Unless you're writing a Tomcat administration webapp, at least.

Having said that, the actual environment variables that the Tomcat scripts employ are named CATALINA_HOME and CATALINA_BASE and the names are case-dependent in most OS's. But if you're running Tomcat using the WTP plugin that comes with Eclipse, it meddles considerably with Tomcat's internal configuration and, as I'm always happy to point out, badly.

So first, rethink why you need to know where Tomcat lives. Secondly, realize that trying to find that location from inside a webapp might not work in all environments. As a rule, a better way to get absolute filesystem paths in webapps is to inject them via JNDI. But even so, the path where Tomcat lives isn't generally good to know.

And whatever you do, don't assume that the "current directory" is related to CATALINA_HOME or CATALINA_BASE. Absolutely nothing in the J2EE or JEE specs supports current directories, so if you use the general Java functions to locate the current directory, you may discover that it changes unreliably and with no predictable relation to anything. There's only one "current" directory for the entire VM, but a Tomcat server is full of unrelated threads that could could affect what that directory is. Maybe not today, maybe not next week. But maybe, and Murphy's Law has something to say about that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!