Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

How do I get JBoss 4.0.2 to read a properties file?

Thread view: 
Kermit Piper - 24 Feb 2006 19:38 GMT
Hello,

I cannot seem to get a response from the forums at JBoss.org, so I
thought I'd try here. I have a properties file (test.properties)
located here:

C:\jboss\server\default\deploy\test.war\config

Here is a sample from the file:
##############################################
#
# General Properties File for TEST  Application
#
##############################################
# database properties
test.db_servername=TEST
test.db_databasename=DEV
test.db_username=xx
test.db_password=xxxxxx

When I start JBoss I get these errors:
17:12:57,370 INFO  [STDOUT] PropertiesManager:
getAttribute(test.db_servername): property not found in
C:\jboss\bin\..\webapps\test\config\test.properties
17:12:57,370 INFO  [STDOUT] PropertiesManager:
getAttribute(test.db_databasename): property not found in
C:\jboss\bin\..\webapps\test\config\test.properties
17:12:57,370 INFO  [STDOUT] PropertiesManager:
getAttribute(test.db_username): property not found in
C:\jboss\bin\..\webapps\test\config\test.properties
17:12:57,370 INFO  [STDOUT] PropertiesManager:
getAttribute(test.db_password): property not found in
C:\jboss\bin\..\webapps\test\config\test.properties
17:12:57,495 INFO  [STDOUT] PropertiesManager:
getAttribute(test.testds_initial_pool_size): property not found in
C:\jboss\ bin\..\webapps\test\config\test.properties

Can someone please explain to me what I'm doing wrong as far as the way
JBoss reads properties files? I've migrated this webapp from
astandalone version of Tomcat to run on embedded Tomcat in JBoss. Any
help would be greatly appreciated.

Thanks,
KP
Raymond DeCampo - 24 Feb 2006 19:50 GMT
> Hello,
>
[quoted text clipped - 37 lines]
> astandalone version of Tomcat to run on embedded Tomcat in JBoss. Any
> help would be greatly appreciated.

What is this PropertiesManager class?  Why is it looking for the file in
C:\jboss\bin\..\webapps\test\config\test.properties?

My guess is that PropertiesManager is your own class and you've
hardcoded the path to your properties file relative to the working
directory of tomcat.  No surprise it doesn't work in JBoss.

If so, you've been a bad little Java coder.  To redeem yourself, place
the properties file in the classpath for the web application (you do
know where that is, right?) and load it either via ResourceBundle or
ClassLoader.getResource().

HTH,
Ray

Signature

This signature intentionally left blank.

Kermit Piper - 24 Feb 2006 20:00 GMT
Thanks Raymond. I'll give it a try.

> Hello,
>
[quoted text clipped - 40 lines]
> Thanks,
> KP
Kermit Piper - 25 Feb 2006 10:02 GMT
Hello,

Where would I place the properties file in the classpath for the web
application and how would I load it either via ResourceBundle or
ClassLoader.getResource(). I'm honestly not sure about how to go about
this.

Thanks,
KP

> Hello,
>
[quoted text clipped - 40 lines]
> Thanks,
> KP
Raymond DeCampo - 25 Feb 2006 19:42 GMT
> Hello,
>
> Where would I place the properties file in the classpath for the web
> application and how would I load it either via ResourceBundle or
> ClassLoader.getResource(). I'm honestly not sure about how to go about
> this.

Kermit,

The classpath for a web application includes the WEB-INF/classes
directory in the war archive and all jars found in the WEB-INF/lib
directory of the war archive.  I imagine you will want to place your
property file in the WEB-INF/classes directory.

Once your properties file is in the classpath, it is easy to access it
via the java.util.ResourceBundle class.  Simply use the
ResourceBundle.getBundle() method and pass the name of the property
bundle (i.e. the name of the file without the .properties extension).

I suspect however that you already have some code you would like to
salvage that does not use a ResourceBundle, but accesses the properties
file like a file.  In that case, you can get an input stream for any
file in the classpath by using the ClassLoader.getResourceAsStream()
method.  Just pass the location of the file relative to the classpath.
For example, "/configuration.properties".

You should take a look at the javadoc for these methods.  Also, managing
a J2EE web application is not for the faint of heart nor is it easy for
people new to Java.  Keep this in mind and expect a steep learning curve.

HTH,
Ray

Signature

This signature intentionally left blank.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.