Solved

Loading properties file from Servlet

Posted on 2006-10-29
4
428 Views
Last Modified: 2013-11-24
Trying to load a properties file from a Servlet and I'm getting null pointer excepion.  I can't figure out

1.  The code

// servet stuff...
Properties myProps = new Properties();
myProps.load(getClass().getResourceAsStream("conf/build.properties");  // << -- thrown from here **
String foo = (String) myProps.getProperty("foo);

2. On my appserver the properties file lives here.
 
$APPDIR/WEB-INF/classes/conf/build.properties

3.  Exception

java.lang.NullPointerException
        at java.util.Properties$LineReader.readLine(Properties.java:365)
        at java.util.Properties.load(Properties.java:293)
        at com.saferX.util.misc.PropertiesUtil.init(PropertiesUtil.java:71)  << -- ** Line marked above.
        at com.saferX.util.misc.PropertiesUtil.<init>(PropertiesUtil.java:43)
        at com.saferX.util.misc.PropertiesUtil.getPropertiesUtil(PropertiesUtil.
java:103)
        at com.saferX.web.action.LoginAction.initVersionInfo(LoginAction.java:20
1)
        at com.saferX.web.action.LoginAction.executeLogin(LoginAction.java:157)
        at com.saferX.web.action.LoginAction.execute(LoginAction.java:52)
        at org.apache.struts.action.RequestProcessor.processActionPerform(Reques
tProcessor.java:421)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:226)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:116
4)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:154)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
        at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterC
hain.java:106)
        at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain
.java:173)
        at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocatio
n.java:229)
        at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:274
)
        at com.caucho.server.port.TcpConnection.run(TcpConnection.java:511)
        at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:516)
        at com.caucho.util.ThreadPool.run(ThreadPool.java:442)
        at java.lang.Thread.run(Thread.java:595)
java.lang.NullPointerException
        at java.util.Properties$LineReader.readLine(Properties.java:365)
        at java.util.Properties.load(Properties.java:293)
        at com.saferX.util.misc.PropertiesUtil.init(PropertiesUtil.java:59)
        at com.saferX.util.misc.PropertiesUtil.getProperty(PropertiesUtil.java:1
31)
        at com.saferX.web.action.LoginAction.initVersionInfo(LoginAction.java:20
5)
        at com.saferX.web.action.LoginAction.executeLogin(LoginAction.java:157)
        at com.saferX.web.action.LoginAction.execute(LoginAction.java:52)
        at org.apache.struts.action.RequestProcessor.processActionPerform(Reques
tProcessor.java:421)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja
va:226)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:116
4)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:154)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
        at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterC
hain.java:106)
        at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain
.java:173)
        at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocatio
n.java:229)
        at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:274
)
        at com.caucho.server.port.TcpConnection.run(TcpConnection.java:511)
        at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:516)
        at com.caucho.util.ThreadPool.run(ThreadPool.java:442)
        at java.lang.Thread.run(Thread.java:595)

------------------------------------------------------------------------
How do I fix it and read property 'foo' from that properties file?
0
Comment
Question by:tmonteit
  • 3
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17829623
Try

myProps.load(getClass().getResourceAsStream("/conf/build.properties");
0
 

Author Comment

by:tmonteit
ID: 17829842

I'm confused What's different than what I'm already trying?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 17829886
You have no opening forward slash
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17830317
:-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate insert example 13 34
ejb stateless example 2 27
Desingning Refactoring existing code 2 26
How to configure empty element in XML Document parser? 15 36
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question