The absolute number one cause of problems which occur in production but not in development is Environment.
Your production machine is, more likely than not, configured very differently from your development machine. You might be developing your Java application on a Windows PC whilst deploying to a Linux-based server, for example.
It's important to try and develop against the same applications and libraries as you'll be deploying to in production. Here's a quick checklist:
- Ensure the JVM version you're using in development is the exact same one on the production machine (
java -version
).
- Ensure the application server (e.g. Tomcat, Resin) is the same version in production as you're using in development.
- Ensure the version of the database you're using is the same in production as in development.
- Ensure the libraries (e.g. the database driver) installed on the production machine are the same versions as you're using in development.
- Ensure the user has the correct access rights on the production server.
Of course you can't always get everything the same -- a lot of Linux servers now run in a 64-bit environment, whilst this isn't always the case (yet!) with standard developer machines. But, the rule still stands that if you can get your environments to match as closely as possible, you will minimise the chances of this sort of problem.
Ideally you would build a staging server (which can be a virtual machine, as opposed to a real server) which has exactly (or as close as possible to) the same environment as the production server.
If you can afford a staging server, the deployment process should be something like this:
- Ensure application runs locally in development and ensure all unit and functional tests pass in development
- Deploy to staging server. Ensure all tests pass.
- Once happy, deploy to production