Pages

March 20, 2010

Where Are My Configuration Files???

I recently was tasked to migrate an application that was hosted in a Windows environment to a Linux environment.  It is a Java/JEE web application so I initially thought it would be a quick task.  I installed my JDK and JBoss Application Server on the Linux box and then deployed the WAR file. I pulled up my browser to hit the app and got nothing but stack traces… Not what I expected.

So I did the obvious thing and looked through the logs and found that some configuration files were missing. No problem, except the file names were all hard coded to locations on the Windows C: drive. This is where a big problem lies as there is no C: drive on Linux boxes. Initially, I thought the best solution would be to just use System.getProperty() to get the current OS and use a different path based on what as returned, but the more I thought about it, the more naive that solution appeared to be. It would add more if/else branches in the code and would require future changes if the decision was ever made to move to a different OS. So I went back to the drawing board, and eventually the most obvious and simple solution came to me. USE AND ENVIRONMENT VARIABLE FOR THE CONFIGURATION FILE DIRECTORY!!!

I don’t know why I didn’t think of it sooner. By using an environment variable to store the configuration file directory I can simplify the code and will never have to update it for future OS environments. In the meantime, to run the app all that will need to be done to ensure the app gets its configuration is just add another environment variable. I am pleased with this.