Java Web Deployment: build code, or deploy .war?

I'm firmly against building on the production box, because it means you're using a different build than you tested with. It also means every deployment machine has a different JAR/WAR file. If nothing else, do a unified build just so that when bug tracking you won't have to worry about inconsistencies between servers.

I'm firmly against building on the production box, because it means you're using a different build than you tested with. It also means every deployment machine has a different JAR/WAR file. If nothing else, do a unified build just so that when bug tracking you won't have to worry about inconsistencies between servers.

Also, you don't need to put the builds into version control if you can easily map between a build and the source that created it. Where I work, our deployment process is as follows. (This is on Linux, with Tomcat.) Test changes and check into Subversion.

(Not necessarily in that order; we don't require that committed code is tested. I'm the only full-time developer, so the SVN tree is essentially my development branch. Your mileage may vary.

) Copy the JAR/WAR files to a production server in a shared directory named after the Subversion revision number. The web servers only have read access. The deployment directory contains relative symlinks to the files in the revision-named directories.

That way, a directory listing will always show you what version of the source code produced the running version. When deploying, we update a log file which is little more than a directory listing. That makes roll-backs easy.

(One gotcha, though; Tomcat checks for new WAR files by the modify date of the real file, not the symlink, so we have to touch the old file when rolling back. ) Our web servers unpack the WAR files onto a local directory. The approach is scalable, since the WAR files are on a single file server; we could have an unlimited number of web servers and only do a single deployment.

If the war is treated as sacred, it seems it ought to go in version control... – davetron5000 Sep 26 '08 at 21:48 For one thing, I'm not confident I can create it purely from source. Things don't get checked into SVN properly, or I need a special test-on-production-environment build for hard to reproduce bugs. For another thing, we've got backups for WARs; SVN history is used for debugging, not roll-backs.

– David Leppik Oct 15 '08 at 16:10 You can have automated deployment procedures on the production boxes, but don't do building on them (because you then need to test the build etc. Etc). – Thorbjørn Ravn Andersen Jul 3 '10 at 11:48.

Most of the places I've worked have used the first method with environment specific configuration information deployed separately (and updated much more rarely) outside of the war/ear.

I highly recommend "Deploy assembled artifacts to production box" such as a war file. This is why our developers use the same build script (Ant in our case) to construct the war on their development sandbox, as is used to create the finally artifact. This way it is debugged as well as the code itself, not to mention completely repeatable.

There exist configuration services, like heavy weight ZooKeeper, and most containers enable you to use JNDI to do some configuration. These will separate the configuration from the build, but can be overkill. However, they do exist.

Much depends on your needs. I've also used a process whereby the artifacts are built with placeholders for config values. When the WAR is deployed, it is exploded and the placeholders replaced with the appropriate values.

I would champion the use of a continuous integration solution that supports distributed builds. Code checked into your SCM can trigger builds (for immediate testing) and you can schedule builds to create artifacts for QA. You can then promote these artifacts to production and have them deployed.

This is currently what I am working on setting up, using AnthillPro. EDIT: We are now using Hudson.

1 Ditto that answer except that we use the open source build server Hudson instead. Build servers that are automatically building, testing, and generating all your build products for testing and deployment are a good thing. – John Munsch Oct 7 '09 at 15:32.

Updated with a concrete scenario, see above.

If you are asking this question relative to configuration management, then your answer needs to be based on what you consider to be a managed artifact. From a CM perspective, it is an unacceptable situation to have some collection of source files work in one environment and not in another. CM is sensitive to environment variables, optimization settings, compiler and runtime versions, etc.And you have to account for these things.

If you are asking this question relative to repeatable process creation, then the answer needs to be based on the location and quantity of pain you are willing to tolerate. Using a . War file may involve more up-front pain in order to save effort in test and deployment cycles.

Using source files and build tools may save up-front cost, but you will have to endure additional pain in dealing with issues late in the deployment process. Update for concrete example Two things to consider relative to your example. A .

War file is just a . Zip file with an alternate extension. You could replace the configuration file in place using standard zip utilities.

Potentially reconsider the need to put the configuration file within the . War file. Would it be enough to have it on the classpath or have properties specified in the execution command line at server startup.

Generally, I attempt to keep deployment configuration requirements specific to the deployment location.

Using 1 packaged war files for deploys is a good practice. We use ant to replace the values that are different between environments. We check the file in with a @@@ variable that will get replaced by our ant script.

The ant script replaces the correct item in the file and then updates the war file before the deploy to each To summarize- ant does it all and we use anthill to manage ant. Ant builds the war file, replaces the file paths, updates the war file, then deploys to the target environement. One process, in fact one click of a button in anthill.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions