Skip to content

Platform dependent artifacts

Example with JMS-client

While we strive to make our artifacts platform independent, this is not always possible. The java.naming.factory.initial-property needed by JndiTemplate requires that the given implementation of ContextFactory is present on the classpath. Putting the property in a external property-file is a good idea and makes the Spring-setup environment independent. However, switching between multiple jms-servers requires different jar-files.

Switch jar-files directly with assembly

If different jar-files is the only difference, and all combinations are relevant, assembly seems a suitable choice.

  1. Create a component that includes everything that is common.
  2. Create one component and one assembly descriptor for each different jms-implementation

Switch jar-files using profiles

If you have other changes in addition to switching dependency or you just are interested in one assembly or the other, use profiles. Here is how to implement:

Use profiles to choose which dependency to include.

jmsImpl_activemq jmsImpl activemq activemq org.apache.activemq activemq-core 5.1.0 jmsImpl_weblogic !jmsImpl weblogic bea.weblogic wlclient 9.2.0.0 bea.weblogic wljmsclient 9.2.0.0

Note that if _jmsImpl_ is not set, we use weblogic by default. ActiveMQ can be used by using _-DjmsImpl=activemq_. 

The jmsImpl-property should be used as part of the assembly outputname to illustrate which jms-implementation it supports. [Classifier | http://maven.apache.org/plugins/maven-assembly-plugin/assembly-mojo.html#classifier] is the natural choice, but it is also possible to postfix it to the finalName. 
org.apache.maven.plugins maven-assembly-plugin $-$