Using maven for multiple deployment environment (production/development)?

I think that Maven WAR overlays could be your answer.

FYI best practice is to not have to rebuild your artifact for different environments - as that does not lead to re-produceable builds, and other things could potentially change when rebuilding. I.e. Using resource-filtering, as suggested above, only works when re-building your project.

When you graduate an artifact from dev to test or acceptance test to production - you do not want to have to rebuild. What you want to do, is actually have your configuration dynamic, dependent on run-time variables. I.e.

Different spring setups or properties files for differenent environemnts e. G: d db-dev. Properties db-test.

Properties db-prod. Properties Then you can switch between these configurations using run-time variables and Spring's PropertyPlaceholderConfigurer. You can also actually use diferent spring configuration files as well, as I've done in the past, for more complex setups.

I also suggest you leave your 'default' setup as production - so that if you deploy to production, you don't need to worry if you forget to set the environment variable.

I agree about not having to rebuild the artefact to move from development to production. How do you get spring to load different contexts at runtime based on a runtime variable, say a system property? – mdma Apr 7 at 9:52.

If you want to delete ant from your process, I would look at using build profiles with filters. In this scenario, plug your properties files into the src/main/resources tree structure. Then parameterize the properties file with filter properties like this: jdbc.

Url=${filtered.jdbc. Property} Then inside src/main/filters create filter files based upon profiles. So you could have dev-filters.

Properties sit-filters. Properties, etc. These contain: filtered.jdbc. Property=jdbc url here Then you setup build profiles for each region where you set an env property pointing to the particular region your building.

You can then setup the resources filter to use ${env}-filters. Properties for each build. Additionally, you can setup the war plugin to add the env property to your artifact so that you actually store 4 different artifacts in your repository under a different classifier.

You then simply build the app with each profile. You have to call the build for each profile, but it does work well. Example of some settings in the POM: src/main/filters/filter-${env}-application.

Properties src/main/resources true maven-war-plugin 2.1-beta-1 package war ${env} LOCAL true LOCAL DEV DEV UAT UAT PROD PROD Also, props to this blog post which is where I originally found the steps to accomplish this.

This works, but I think it is much better to have one artefact deploy everywhere, like Antony Stubbs suggests. In larger software projects you'll have many environments where you deploy the stuff (production, testing, development environment, each developer machine), and to build different WARs for each of those is a pain. – hstoerr Jul 20 '09 at 5:52 Well, it depends.

Building a different war for each region is simple using Hudson. I just copy the configuration, create a new nightly build and change the profile it builds with. These builds are deployed to Nexus, which means if anyone wants it, they can pull from Nexus or look at Hudson to see what it does.

If you're not using a CI system, I can see how it might be a pain. I find the risk to be very low as all I'm changing are properties files...Everything else is a jar that's been tested in a different Maven project. – Mike Cornell Jul 20 '09 at 13:03.

I have handled this using Spring's PropertyPlaceholderConfigurer and including property files on the classpath and one on the filesystem: If there is a myapp*. Properties file in the current directory when the app starts (or tests are run etc. ) it will override properties from files baked into the war/ear/whatever.

There's this article about it on maven 2 using build profiles. It looks like it just delegates to ant anyways via the antrun plugin so you might even be able to get away with re-using your existing build. Xml files.

This spells it out pretty well, uses the build profiles as @seth mentioned- maven.apache.org/guides/mini/guide-build....

If you want to delete ant from your process, I would look at using build profiles with filters. In this scenario, plug your properties files into the src/main/resources tree structure. Then inside src/main/filters create filter files based upon profiles.

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