Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

context path in java class

 
Avinash venna
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

i am using servlets and jsp's for my web application... through servlet i am calling a java class and that class reads a property file.. when i am working on eclipse i gave the absolute path for the file.. but after deploying the class is unable to retrieve the exact path... someone please help me how to give a file location in web context (this file is read by a normal java class.. not a servlet or jsp)
 
Rahul Nair
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Avinash,

In servlet you are calling a java class means at the top, you should have written import statement for that class. Then in that case there should not be any problem after deploying the class... Can you please share some line of code so that we can investigate it ?

Thanks

Rahul
 
Nilesh Miskin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always use paths that are relative to the context root of the web app. That way you can ensure that your class gets the desired resources.
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the getResourceAsStream() method of the ServletContext to read the properties file as stream. I am assuming your properties file is not outside the web application

Since your are reading the properties file in a non servlet class, get the stream in a servlet and pass the InputStream to your java class.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic