witzar
witzar

Reputation: 770

Web-application configuration outside or inside war file?

A web application usually has at least one configuration file, that contains jdbc configuration and other settings. You can put such file(-s) inside a .war file or outside it. What are the cons and pros of these approaches? What is your approach and why?

Upvotes: 13

Views: 3600

Answers (4)

Marquez
Marquez

Reputation: 6039

In my opinion an application setting value should never be merged with a binary. They should be placed in a separate file or database. This is a basic best practice. You never know when you or anyone else will need to adjust one of the settings -- and you may not be around -- or the source code may not be available.

Upvotes: 2

WildWezyr
WildWezyr

Reputation: 10751

IMHO the best way is to use flexible approach and allow config to be inside and/or outside WAR (with some extra logic for config lookup order and what file/dir names that config may be kept in).

I have experience with extremely different deploy models/schemas - sometimes it is one build/many configs, other time - even: many builds/one config on one server - strange, but can happen ;-).

This may be especially helpful if you are developing some kind of platform that your customers/users may deploy in custom environments unspecified at WAR build time.

Upvotes: 1

HeDinges
HeDinges

Reputation: 4607

Imho, outside seems the most convenient if you need to deploy the same war in different environments. Like, dev, itt, uat and production. Same build different configurations.

Upvotes: 9

Bozho
Bozho

Reputation: 597106

Put them inside the war and use some sort of build-profiles (like maven build profiles). That way:

  • you have one-step deployment. No manual editing of properties on remote environments.
  • you can have different artifacts (war files) for different environments, so the build is still portable, but you don't need to open wars with a ZIP software to modify settings.

The way to implement/use the build profiles depends on your build environment.

Upvotes: 1

Related Questions