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

K

Kermit Piper

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
 
R

Raymond DeCampo

Kermit said:
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.

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
 
K

Kermit Piper

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
 
R

Raymond DeCampo

Kermit said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top