I have a GlassFish/j2ee application, and I develop on one box, and production is a remote box. I have a function that makes files, and I need the files' location to be different based on my dev box or production. What is an automatic way to do the switching so I do not have to edit the source file based on where it is being deployed?
The easiest approach is to define a system property which specifies where the file system location for your data is. The production appserver would define one value (using java -D
in the startup script), and your dev app server would define another value. Your application source would consult the system property value (using System.getProperty()
) to discover the appropriate location.
Essentially you are trying to store arbitrary data that changes depending on your environment. If you you currently do that in your app (ie a database) I would just put it in there.
Put the information you need in JNDI - that's what it is designed for.
Consider letting your application refuse to do anything if the information is not there.
You can use a properties
file and externalize environment specific stuff (like your "file location") in this configuration file. Put the adequate value in it at build time (e.g. using filtering and profiles with Maven). Include this file in the application or make it available somewhere on the classpath.