Discussions

General J2EE: How to find .properties file?

  1. How to find .properties file? (1 messages)

    Hi,

    how can I find a .properties file from a class deployed in a jar/war/ear without coding any absolute path informations into the source? Note that the class in question does not have to be an EJB, but will be loaded/used/referenced by one...

    Thanks,
    Lars
  2. How to find .properties file?[ Go to top ]

    You can use your classes ClassLoader to find your property files.

    Properties p = new Properties();

    InputStream in = yourclass.getClassLoader().getResourceAsStream("my.properties");

    //If the resource is not found , null is returned.
    if( in != null)
    p.load(in);

    xxx...

    If you don't want to 'hard code' the properties file name,
    set it up as an environment entry the respective deployment descriptor.


    TK.