Often JEE applications contain property files with environment specific information. Because deployment should be automated, you need some way of dealing with these property files. Basically you have three options:
- Put a default property file in the ear and edit it after deploying it to the server. This means you have to do some scripting with Perl or some other language.
- Choose the property file to put in the ear before you deploy. If you choose this option, you need to know the correct property values in advance. Further more, you need to tell maven or ant which property file to deploy by setting some sort of environment flag
- Store the property file on the system classpath instead of in the ear. This has the disadvantage that you need to restart the server every time you want to change something in the file.
Usually property files are application specific, so I prefer either of the first two options. The other day, however, I got a call from someone who needed to store the property file on the servers' classpath.
Of course(!?) every application server is different. In IBM Websphere you put property files in the [WAS_HOME]/appserver/properties directory and configure the server, so it knows where to find the property file.
(NB: for those of you who have been looking for this feature: it is hidden under Application Servers > [server] > Process Definition > Java Virtual Machine - Custom Properties) The Oracle application server doesn't have a folder like that, nor does it have any options to specify property file locations. So where do you put property files if you want to put them on the system classpath? The Oracle container (OC4J) has two possible candidates for this property file:
- the applib directory
- shared-lib directory.
I decided to do a little test: I created a test application that displays the values in a property file. I used the standalone OC4J(10.1.3) for this test, but it works the same way in the Oracle Application Server 10g. First I tried the applib directory. I deployed the application to the OC4J, stopped the server and copied the property file into the [ORACLE_HOME]/j2ee/home/applib directory. Then I restarted OC4J. The web application displayed the values in the property files correctly. Next, I removed the property file from the applib directory and put it in the [ORACLE_HOME]/j2ee/home/shared-lib directory. I restarted the server and tried again. This time, the property file was not found.
This made me wonder about the differences between the two. The applib directory is used by all applications. Libraries and other files that are put in this directory are loaded before libraries and files in the WEB-INF/lib directory of your ear file. In the Oracle® Containers for J2EE Developer’s Guide 10g Release 2 (10.1.3) , shared libraries are explained in great detail. Basically you use these if you have an application that needs to use a different library than the standard library that is packaged with OC4J. An example can be the XML Parser you want to use, or a different version of the Oracle JDBC driver. Another reason to use shared libraries is to share proprietary classes across specific applications, rather than across all applications. To accomplish this, you obviously need to configure your application to work with the shared libraries. The developers guide describes the steps to do this. So if I really wanted to try if the shared-lib folder works for the property file, I would have to configure the shared libraries and my application. I decided not to bother...I am not sure what happens if the application is clustered, but since this was not a requirement when I got the question, the applib directory looks like the simplest solutions that could work in this particular case.
