Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

get tomcat webapps directory into java class  RSS feed

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
I have some java class that jsp pages are calling it methods
this class is reused and I don�t want to relay on ServletContext.application.getRealPath
to find the conf file this class is using . is the any global way to read/find path to file both under tomcat and out side it?
thanks
 
Joe Ess
Bartender
Posts: 9428
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a couple of options. The easiest is to pass the path of your config file in as a system property value in the virtual machine:

Then you read the value in your program using:

If you are packaging your web application as a WAR or EAR, you can place your config file in the classpath and load it with the classloader:

The java.util classes Properties and ResourceBundle build upon these capabilities with built-in parsing to make this task even easier.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!