Where can I put a property file unique to my domain?

Imagine a scenario where you have an application that needs to have resources configured based on where the application is deployed, but you also want to deploy the application "unaltered" in different environments. A simple example is specifying a working directory for an application, and you deploy that application in development, testing, and production, but don't want to use the database as your configuration component.

A domain wide property file can be a good solution. It requires no changes to the EAR, is DB independent, and it survives redeploys as well.

So where would you put such a file?

Property files historically are loaded via Classloader.getResource and its related methods. That means that the property file needs to be put on the classpath.

On the server, you could easily simply add a to the servers classpath to some known location, and place your property files there.

But there is already a domain specific area for libraries and classes that are visible to the server ClassLoader.

Let's assume that $domain equals your domain directory (In a generic windows install, this might be C:\Sun\AppServer\domains\domain1 for the default domain).

Then, a standard location to deploy your property file would be:

$domain/lib/classes

So, you could put examples.properties in to this directory for use by your application.

In order to access this property file, you could use the following code snippet:

public Properties loadProperties() throws IOException {
    Properties prop = new Properties();
    InputStream is = this.getClass().getClassLoader().getResourceAsStream("examples.properties");
    if (is != null) {
        try {
            prop.load(is);
        }
        finally {
            // Forgetting to close input streams from property loaders
            // is a common source of resource leaks in applications.
            is.close();
        }
    }
    return prop;
}

This method will work both in an EJB, or within a WAR since the $domain/lib/classes directory is on the Classpath for both components.