Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Loading properties file from Servlet

Posted on 2006-10-29
4
Medium Priority
?
433 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 2000 total points
ID: 17829886
You have no opening forward slash
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17830317
:-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
A solution for Fortify Path Manipulation.
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 video teaches viewers about errors in exception handling.
Suggested Courses

721 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