Dave
Dave

Reputation: 21924

Should Maven package different WARs for different application servers?

I am just starting to package my web application project as a WAR file and am running into differences between the configuration for Tomcat vs Jetty vs JBoss vs Websphere, etc.

Should I try to configure some super-smart an all-in-one WAR file, or should I create different Maven profiles to create different WARs for each app server?

I don't think I should create a separate Maven module for each app server WAR, should I?

Upvotes: 0

Views: 974

Answers (2)

Julian Simpson
Julian Simpson

Reputation: 617

I try never to ship configuration inside a war. The code shouldn't care what environment it's shipped into. It makes deployment more complex, but the flip side is that you can easily push out a config change and have to be concerned about accidentally deploying code changes to an environment.

This advice applies doubly in this case as it seems like you have the challenge of different environments and different containers.

Upvotes: 1

Barend
Barend

Reputation: 17444

I would initially try to get that working with one super-smart war. I don't know what problems you run into, exactly, but jboss-web.xml and jetty-web.xml should be able to coexist in one WEB-INF.

If reality isn't so generous, I would use the war overlays feature and version classifiers. Filesystem structure and pom.xmls would be like this:

myproject                (packaging: pom, version: 1.0.0-SNAPSHOT)
+-- myproject-war        (packaging: war, version: 1.0.0-SNAPSHOT)
+-- myproject-war-jboss  (packaging: war, version: 1.0.0-jboss-SNAPSHOT)
+-- myproject-war-jetty  (packaging: war, version: 1.0.0-jetty-SNAPSHOT)

The two appserver-specific wars contain just the appserver-specific files and import the plain war as an overlay. Three different war's get deployed into your Maven repository, differing in version number only by the classifier part (e.g. myproject-war-1.0.0-jboss).

Ideally, you'd get the versioning set up in pom.xml with something like <version>${project.parent.version}-jboss</version>, but I'm not entirely sure that can be combined with the SNAPSHOT classifier and still work.

Upvotes: 6

Related Questions