Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Lost properties

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I'm having a little trouble with a DB conn pool I'm setting up.
The details of the database (name, location, user/pwd, etc) are all stored in a properties file, so that if anything changes, it's a simple change to the properties file rather than code.

Prolem is, I can't find a way of getting this Init class to see the properties file. I don't want a full local path (C:\...\...\...\) I would need it to be a relative path. I have asked about this before and was under the standing that the WEB-INF folder was the place to have properties files, but my class still can not see it

ERROR: FileNotFoundException

CODE:
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your code inside a servlet? If yes, then you can simply use getServletContext().getResourceAsStream("/WEB-INF/properties/dbconn.properties");
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Code is not in a Servlet, but is called by a Servlet.

ERROR:


CODE:


SERVLET CALL:


[ August 17, 2007: Message edited by: Keith Wilson ]
[ August 17, 2007: Message edited by: Keith Wilson ]
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

getClass().getResource("/WEB-INF/properties/dbconn.properties");


For this to work, the file needs to be in the classpath. Try moving the dbconn.properties file into the "classes" directory (and don't prefix it by "WEB-INF/classes").

Or work with the servlet context, as was suggested before.
 
Let me tell you a story about a man named Jed. He made this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!