• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

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 ?
Saloon Keeper
Posts: 22273
Android Eclipse IDE Tomcat Server Redhat Java 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.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic