• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Help with using getResourceAsStream()

 
Ranch Hand
Posts: 231
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fellow Developers:

Here's my situation... I posted an earlier topic regarding my problem, but since then since the scenario regarding my problem has kind of changed, I decided to make a new thread (all apologies if this was an inappropriate action).

I changed my Ant build script to move the log4j.properties file into my WEB-INF/classes dir. Also, my log4j-1.2.9.jar gets moved inside my WEB-INF/lib dir. But for some odd reason, when I run Tomcat, it doesn't seem to know where my log4j.properties file is! My Log4jInitServlet seems to have the path wrong!

It looks inside:

C:\DevTools\tomcat\jakarta-tomcat-5.5.9\bin\WEB-INF\classes\log4j.properties

instead of:

C:\DevTools\tomcat\jakarta-tomcat-5.5.9\mywebapp\WEB-INF\classes\log4j.properties.

Furthermore, it throws a NullPointerException but at the same time, right afterwards, it logs my XmlConfigInitServlet (I have it set
there!).

Here's what my console says:



My Log4jInitServlet:



My web.xml:



My XmlConfigInitServlet class (as you can see that I am still using getRealPath()) but will change it when I get my Log4jInitServlet properly set up. For some odd reason, its logging what I have put in here into my Tomcat's console. How could this be if Tomcat complained that it couldn't find my log4j.properties file?



Here's the contents of my log4j.properties file located under mywebapp/WEB-INF/classes:



From the looks of everything, obviously there's a pathing issue in my Log4jInitServlet but I still don't understand how it can successfully log my XmlConfigServlet if my log4j.properties is supposed to be unavailable?! Why is it throwing an NullPointerException?

Can anyone suggest a better way to use getResourceAsStream()? What I am trying to do is set my undeployWars to false in server.xml so that Tomcat can read my log4j.properties file and my xml config file (attributes-config.xml) from within the war file.

Sincerely yours and happy holidays,

James Dekker

[ December 22, 2006: Message edited by: James Dekker ]
[ December 22, 2006: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that the actual code you are running? Because I would expect this line of codeto be searching for a resource named "com.acme.mywebapp.logging.propFile". The most likely location for such a file would be in your WEB-INF/classes/com/acme/mywebapp/logging directory. (You seem to be using a constant string instead of a variable name, but your method of getting what's in that variable isn't going to work anyway.

What I would do is this: put the log4j.properties file in your WEB-INF/classes directory and use this line of code to access it...
 
James Dekker
Ranch Hand
Posts: 231
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,

Thanks for the response!

I actually got it working (and when the undeployWars="false" in server.xml, it still works!), like this:



Now, the problem is... How do I make it so that the PropertyConfigurator would work with this?

If I un-comment out the lines of code which hold comments, I get this a NullPointerException:



Thank you for the response,

-JD
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this line 16?:


If so, why are you trying to read the absolute path name from a file that you can't find?

Why not just use the string value that you obtained with:
getServletContext().getInitParameter("log4j-init");
?
[ December 23, 2006: Message edited by: Ben Souther ]
 
Get me the mayor's office! I need to tell her about this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic