Hi,
SAR files are called as Service Archives. The extension of SAR files are *.sar which contains a “META-INF/jboss-service.xml” file, this file describes the custom MBeans which has to be exposed at the time of deployment or JBoss Startup. JBoss’s service archive architecture is based on the JMX and the SAR files which are basically JBoss specific can be deployed in the jboss inorder to publish your MBean based services. At the time of JBoss startup these service archive deployer (SARDeployer) instantiates the JBoss service classes and exposes them as manageable beans through JMX. These beans can be viewed and edited from the jmx-console as well.
You can refer to the sample of creating service archives in JBoss AS6 in the following link: http://middlewaremagic.com/jboss/?p=307 .
But in JBoss AS 7 it is little different as the class “org.jboss.system.ServiceMBean” and “org.jboss.system.ServiceMBeanSupport” are not present in JBoss AS7. Also the JBoss AS 7 service descriptor (jboss-service.xml) file requires XSD declaration, And without the XSD declaration inside jboss-service.xml file you will see the following kind of Exception while deploying your SAR file.
23:10:52,007 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.deployment.unit."ServerMonitorService.sar".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."ServerMonitorService.sar".PARSE: Failed to process phase PARSE of deployment "ServerMonitorService.sar" at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:121) at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765) at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_21] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_21] at java.lang.Thread.run(Thread.java:619) [:1.6.0_21] Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: Failed to parse service xml ["/home/userone/jboss-as-7.0.1.Final/standalone/deployments/ServerMonitorService.sar/META-INF/jboss-service.xml"] at org.jboss.as.service.ServiceDeploymentParsingProcessor.deploy(ServiceDeploymentParsingProcessor.java:94) at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:115) ... 5 more Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[3,1] Message: Unexpected element 'server' at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:98) at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:59) at org.jboss.as.service.ServiceDeploymentParsingProcessor.deploy(ServiceDeploymentParsingProcessor.java:87)
Also in JBoss AS7 we need to implement the start() and stop() service if we want to perform some specific operations while jboss starts and stops the service. So here we will try to develop a Service Archive in this sample.
Step1). Create a directory somewhere in your file system like “/home/userone/ServerMonitorService.sar”.
Step2). Create an MBean interface “MyServerMonitorMBean.java” inside the “/home/userone/ServerMonitorService.sar” directory.
package custom.mbean; public interface MyServerMonitorMBean { public void setFrequency(String frequency); public String getFrequency(); }
Step3). Now provide an implementation class of the above MBean interface as “MyServerMonitor.java” inside the directory “/home/userone/ServerMonitorService.sar”. And implement the start() and stop() service if we want to perform some specific operations while jboss starts and stops the service.
package custom.mbean; import javax.management.*; import java.io.*; import java.util.*; import java.rmi.*; import javax.naming.*; public class MyServerMonitor implements MyServerMonitorMBean { boolean flag=true; public String Frequency; public MyServerMonitor() { System.out.println("nnt ServiceMonitorMBean is activated...inside ServiceMonitor() constructor--setting default Frequency=10000 Miliseconds");; } public void setFrequency(String Frequency) { System.out.println("nt Server Watch Frequency is set to : "+Frequency+"-Milliseconds"); this.Frequency=Frequency; } public String getFrequency() { System.out.println("nt Server Watch Frequency is set to : "+Frequency+"-Milliseconds"); return this.Frequency; } public void start() throws Exception { System.out.println("nntStarting start() MyServerMonitor invoked"); Frequency="3000"; } public void stop() throws Exception { System.out.println("nntStopping stop() MyServerMonitor invoked"); } }
Now compile the above Codes as following
cd /home/userone/ServerMonitorService.sar/ javac -d . *.java
Step4). Now the most important part, here we need to declare the MBean inside the “/home/userone/ServerMonitorService.sar/META-INF/jboss-service.xml” file as following:
<?xml version="1.0" encoding="UTF-8"?> <server xmlns="urn:jboss:service:7.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd"> <mbean code="custom.mbean.MyServerMonitor" name="service.server.monitor:service=MyMonitor"> <attribute name="Frequency">5000</attribute> </mbean> </server>
NOTE: The XSD declaration is required without that you will see parsing error while deploying your service.
Step5). Deploy the “ServerMonitorService.sar” inside the “jboss-as-7.0.1.Final/standalone/deployments” directory of your JBoss. After deploying the service archive you may see the following Message in server’s Console Stdout….Because the “ServerMonitorService.sar” which we are trying to deploy is in Exploded format:
23:19:17,410 INFO [org.jboss.as.deployment] (DeploymentScanner-threads - 1) Found ServerMonitorService.sar in deployment directory. To trigger deployment create a file called ServerMonitorService.sar.dodeploy
Step6). So create an empty file with name “ServerMonitorService.sar.dodeploy” inside “jboss-as-7.0.1.Final/standalone/deployments” to tell jboss to deploy this Service Archive.
NOTE: If you don’t want to see the message which is displayed in Step5) and don’t want to follow Step6).. then deploy your SAR file as an archive file. (similar to how we create jar/war/ear files using jar utility)
JIRA related to current demonstration: https://issues.jboss.org/browse/AS7-887
.
.
Thanks
Middleware Magic Team
December 22nd, 2011 on 10:53 pm
Thanks for the info. This article has been helpful. One problem I’m having is that under JBoss5 I would embed my dependent JARs into the SAR. However, under AS7 it does not seem to find my JARs. Has something changed under AS7? Is there a way around this? Thanks, David
December 23rd, 2011 on 11:21 am
Hi kc7bfi,
As many JBoss AS7 users are facing this issue so we developed an article addressing this. Please refer to the following article: http://middlewaremagic.com/jboss/?p=1081 Using JAR file placed inside a SAR in JBoss AS7
.
.
Keep Posting 🙂
Thanks
Middleware Magic Team
April 27th, 2012 on 3:09 pm
I followed the steps but I do not see the lines getting printed anywhere.
Where is the action inside the start method or constructor is performed
April 28th, 2012 on 11:08 pm
Hi acewin,
If your SAR is deployed successfully then the start() should be called by JBoss immediately of the deployment. So you should be able to see the output coming from start() of your Bean in your JBoss Logs/ Console output.
Thanks 🙂
Middleware Magic Team
May 9th, 2012 on 11:10 am
OK, I was able to deploy the Sar and run my statements. But I see there is another issue/question/doubt whatever you call it.
Sar needs to be deployed. I have a question, when a SAR gets successfully deployed. is it only after complete execution of calls inside start method it will successfully deploy.
July 13th, 2012 on 9:24 am
hello,
Thanks. This article is very helpful in creating mbean services. Can anybody please help me in configuring parameter’s descriptions of my mbean, like we used to do in jboss 4.2 using xmbeans??
Thanks & Regards,
Divya Garg
September 12th, 2012 on 6:00 pm
Good day,
Thanks for this article, it has been very helpful.
When I deploy my SAR, I am seeing a ClassNotFoundException.
What am I missing or what have I done wrong?
September 12th, 2012 on 11:38 pm
Hi thr4sh3r,
Can you please let us know where actually you placed the missing Class inside your SAR? Is it in form of a JAR? if you are packaging your Classes as part of a JAR inside your SAR then the following article might be helpful: http://middlewaremagic.com/jboss/?p=1081
Thanks
Jay SenSharma
September 13th, 2012 on 11:04 am
Hi Jay,
Thanks for the reply.
The class that it can’t find is in a package in the SAR.
File.sar/coza.blah.blah.blah.ServiceClass
There is no JAR, it is a simple SAR that I created by following this tutorial.
September 13th, 2012 on 10:59 pm
Hi
I have seen your comment in “https://community.jboss.org/message/759334#759334” Looks like you have not placed the Compiled Classes inside the SAR “TransportService.sar”.
So try the following open a terminal and then compile the code :
cd TransportService.sar
javac -d . coza/blah/blah/blah/TibcoTransportService.java
javac -d . coza/blah/blah/blah/TibcoTransportServiceMBean.java
Thanks
Jay SenSharma
September 18th, 2012 on 12:37 am
I have very similar issue – migrating from AS 4 to AS7. My sar jboss-service.xml:
——————————————–
java:/jms/ABCJndiName
Queue
false
my.company.com
my_channel
my_qm_name
1234
MQJMS_TP_CLIENT_MQ_TCPIP
jboss:service=Naming
——————————————–
when starting jboss 7.1, here is the exception:
15:01:34,331 INFO [org.jboss.as.server] (DeploymentScanner-threads – 2) JBAS015870: Deploy of deployment “mq-config.sar” was rolled back with failure message {“JBAS014771: Services with missing/unavailable dependencies” => [“jboss.mbean.service.”jmx.service.wsmq:service=MyConnectionFactory”.startjboss.mbean.service.jboss:service=Naming.startMissing[jboss.mbean.service.”jmx.service.wsmq:service=MyConnectionFactory”.startjboss.mbean.service.jboss:service=Naming.start]”,”jboss.mbean.service.”jmx.service.wsmq:service=MyConnectionFactory”.createjboss.mbean.service.jboss:service=Naming.createMissing[jboss.mbean.service.”jmx.service.wsmq:service=MyConnectionFactory”.createjboss.mbean.service.jboss:service=Naming.create]”]}
15:01:34,438 INFO [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015877: Stopped deployment mq-config.sar in 96ms
15:01:34,483 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015877: Stopped deployment helloworld.war in 149ms
15:01:34,485 INFO [org.jboss.as.controller] (DeploymentScanner-threads – 2) JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.mbean.service.jboss:service=Naming.create (missing) dependents: [service jboss.mbean.service.”jmx.service.wsmq:service=MyConnectionFactory”.create]
service jboss.mbean.service.jboss:service=Naming.start (missing) dependents: [service jboss.mbean.service.”jmx.service.wsmq:service=MyfConnectionFactory”.start]
15:01:34,486 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads – 1) JBAS014654: Composite operation was rolled back
—————————————
BTW – all class and jar (using local module are configured correctly). Any help are appriciated. Thanks
-Chris
September 18th, 2012 on 12:40 am
java:/jms/ABCJndiName Queue false my.company.com my_channel my_qm_name 1234
MQJMS_TP_CLIENT_MQ_TCPIP
jboss:service=Naming
hmmm, the previous post xml are messed up – try again there
June 13th, 2013 on 1:35 pm
Hi,
Your jboss-service.xml doesn’t validate against jboss-service_7_0.xsd. Any comments on this issue ?