Solved

Loading properties file from Servlet

Posted on 2006-10-29
4
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

751 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