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

Discussion in 'Java' started by Kermit Piper, Feb 24, 2006.

  1. Kermit Piper

    Kermit Piper Guest

    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
    Kermit Piper, Feb 24, 2006
    #1
    1. Advertising

  2. Kermit Piper wrote:
    > 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

    --
    This signature intentionally left blank.
    Raymond DeCampo, Feb 24, 2006
    #2
    1. Advertising

  3. Kermit Piper

    Kermit Piper Guest

    Thanks Raymond. I'll give it a try.

    Kermit Piper wrote:
    > 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
    Kermit Piper, Feb 24, 2006
    #3
  4. Kermit Piper

    Kermit Piper Guest

    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




    Kermit Piper wrote:
    > 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
    Kermit Piper, Feb 25, 2006
    #4
  5. Kermit Piper wrote:
    > 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

    --
    This signature intentionally left blank.
    Raymond DeCampo, Feb 25, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kermit Piper
    Replies:
    1
    Views:
    521
    Tajonis
    Feb 25, 2006
  2. han
    Replies:
    0
    Views:
    465
  3. Jubz
    Replies:
    0
    Views:
    2,210
  4. ddog
    Replies:
    3
    Views:
    7,494
  5. LprzemekL
    Replies:
    0
    Views:
    513
    LprzemekL
    Apr 10, 2008
Loading...

Share This Page