Solved

Loading properties file from Servlet

Posted on 2006-10-29
4
423 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
Comment Utility
Try

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

Author Comment

by:tmonteit
Comment Utility

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

Accepted Solution

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

Expert Comment

by:CEHJ
Comment Utility
:-)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now