File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Testing to connect to DB and MissingResourceException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Testing to connect to DB and MissingResourceException" Watch "Testing to connect to DB and MissingResourceException" New topic
Author

Testing to connect to DB and MissingResourceException

Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Hello there,
I trying to test a simple servlet to connect to Oracle DB (8.1.7) and Jboss (3.0.6). I have .properties file (Connection.properties) which contains url, userid and password to be used to connect to DB. I have placed this file into the WEB-INF/classes directory since this directory is automatically on the CLASSPATH. Here is the exact location:
C:\java\jboss-3.0.6_tomcat-4.1.18\server\default\deploy\jmx-console.war\WEB-INF\classes
(I am using default config of JBoss).
Here is what I do to load the connection properties file:
ResBundle = ResourceBundle.getBundle("Connection");
But here is what I get:
ERROR [STDERR] java.util.MissingResourceException: Can't find bundle for base name Connection, locale en_US
How can I narrow down and figure out why my servlet is unable to locate this file?
TIA!
Amer
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
What do you mean by testing? Are you just manually browsing the web application to make the servlet do something or are you running some kind of unit tests when you get this exception?


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Hi Lesse,
Thanks for your time.
I have a jsp page where I input some values. I want to store these values into a table in the DB. JSP calls the "servlet" (action=contextParh+"/servlet" method="post")that tries to load the "Connection.properties" file as I mentioned in my previous post. Right at this point, I get the exception.
This servlet is not part of any application.
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
My apologies Lasse, I misspelled your name in my previous post.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
(sorry to respond with yet another question...)
What do you mean by the servlet not belonging to any application? Do you mean that the JSP and servlet are part of different applications?
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Please pardon me for not explaining my issue properly.
OK, let me put it this way. All of my stuff I am trying to test is part of a small app. I am using ant to build it and deploy. Everything was going OK until I hit the MissingResourceException. Then I copied my "Connection.properties" file into the WEB-INF/classes folder so that it becomes visible to my servlet (in other words, it is in a directory that is on the CLASSPATH).
But my servlet is not able to see it and I am getting this exception.
Hope this clears any confusions I might have caused.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Can you access the properties file using getClass().getResourceAsStream("Connection.properties") directly?
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Thanks for your time Lasse!
I have solved the problem. All I needed to do was place the "Connection.properties" file into "WEB-INF/classes" directory of my app in the development hierarchy.
But I wonder is this how we should be doing in real life?
Cheers!
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Saeed,
We do that (put properties files in the classes directory) for struts config files. For other config files (like the db properties), we use a separate /config folder and put this folder in the classpath.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Hello Jeanne,
Thanks for the valuable tip.
Does this /config directory has to be somewhere in directory hierarchy of the Web Server (JBoss in my case)?
If yes, where?
Thanks and regards,
Saeed
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

Saeed,
It has to be somewhere on the same machine as JBoss. You pick the directory and include it in your application's classpath.
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Great! I got it.
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Testing to connect to DB and MissingResourceException