I have a servlet that reads in a .properties file on init(). My code (not the one below) works if I have a context-parameter set in my web.xml but I read that a context-parameter is globally accessible and I don't want that as this servlet is just a piece of a bigger web application. I just want to be able to do this using the init-param tag I tried this:
public void init(ServletConfig config) throws ServletException {
try {
String fileName = config.getInitParameter("configFile");
System.out.println(fileName);
File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);
p = new Properties();
p.load(fis);
} catch (IOException e) {
e.printStackTrace();
}
}
but I keep getting file not found exception. I have searched the internet but most people use servlet contexts. How else can I load my properties file without including the context-param tag in my web.xml?
Thanks!
EDIT:
java.io.FileNotFoundException: C:\WEB-INF\classes\myapp.properties (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at java.io.FileInputStream.<init>(FileInputStream.java:79)
at ipadService.ProxyServlet.init(ProxyServlet.java:53)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)