JBoss SAR vs EAR/WAR packaging

nemo picture nemo · Apr 27, 2012 · Viewed 14.8k times · Source

When would I choose to deploy as a JBoss SAR instead of an EAR?

This is more of a general question and I'm looking for guidelines that explain the pros and cons of each deployment model and which one is applicable when.

Answer

CoolBeans picture CoolBeans · Apr 27, 2012

You will build a SAR (service archive) when you want to expand the capabilities of the server. For example, JBoss uses SARs for EJB deployer or messaging. You can create one for your own service monitoring (ie. watch some metrics for one of your custom services). As far as I know SARs are unique to JBoss only.

From my personal experience, I once created a SAR to keep track of a web service. I mainly used the service component to keep track of the length of a list of things that the web service component created. This was one way I could poke in the jmx-console and find out some metrics about the incoming requests to the web service.

SARs are based on JMX specs so it's not difficult to create them. You basically create a standard MBean interface and implement that interface. You will also want to make sure you that you have a jboss-service.xml file in the META-INF directory.

On the other hand WARs and EARs are for standard application packaging where you expect the container to manage and process requests for the application. You don't expect the application to be running as an anonymous service component like you do in case of a SAR packaged application.

Hope this helps!