Author: Lagarde Jeremie
Level: Intermediate
Technologies: CDI, JMX and MBean
Summary: Demonstrates the use of CDI 1.0 and MBean
Target Product: EAP
Product Versions: EAP 6.1, EAP 6.2
Source: https://github.com/jboss-developer/jboss-eap-quickstarts/
This example demonstrates the use of CDI 1.0 and MBean in Red Hat JBoss Enterprise Application Platform. The project also includes a set of Aquillian tests for mbeans.
The example is composed of mbeans. They are as follows :
-
AnnotatedComponentHelloWorld
: This mbean is a managed bean with '@MXBean' annotation. -
MXComponentHelloWorld
: This mbean is a managed bean with 'MXBean' interface. -
MXPojoHelloWorld
: This mbean is a pojo using MXBean interface and declared in jboss-service.xml. -
SarMXPojoHelloWorld
: This mbean is a pojo using MXBean interface and declared in jboss-service.xml in Sar packaging.
The application this project produces is designed to be run on Red Hat JBoss Enterprise Application Platform 6.1 or later.
All you need to build this project is Java 6.0 (Java SDK 1.6) or later, Maven 3.0 or later.
If you have not yet done so, you must Configure Maven before testing the quickstarts.
-
Open a command prompt and navigate to the root of the JBoss EAP directory.
-
The following shows the command line to start the server:
For Linux: JBOSS_HOME/bin/standalone.sh For Windows: JBOSS_HOME\bin\standalone.bat
NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See Build and Deploy the Quickstarts for complete instructions and additional options.
-
Make sure you have started the JBoss EAP server as described above.
-
Open a command propmt and navigate to the root directory of this quickstart.
-
Type this command to build and deploy the archive:
mvn clean jboss-as:deploy
-
This will deploy
helloworld-mbean-webapp\target\jboss-helloworld-mbean-webapp.war
andhelloworld-mbean-service\target\jboss-helloworld-mbean-service.sar
to the running instance of the server.
This quickstart differs from the other quickstarts in that it uses 'JConsole' to access and test the quickstart rather than access an URL in the browser. If you do access http://localhost:8080/jboss-helloworld-mbean-webapp/, you will see a screen shot image of the JConsole application,
The following sections describe how to use 'JConsole' to inspect and test the MBeans.
To connect to the JBoss EAP server using jconsole, open a command prompt and type the following command :
For Linux: JDK_HOME/bin/jconsole
For Windows: JDK_HOME\bin\jconsole.exe
Select JBoss process and connect to it.
You can use JConsole to inspect and use the MBeans :
- Click on the MBeans tab.
- Expand
quickstarts
in the left column of the console. - Under
quickstarts
, you see the 4 MBeans:AnnotatedComponentHelloWorld
,MXComponentHelloWorld
,MXPojoHelloWorld
, andSarMXPojoHelloWorld
- Expand each MBean and choose:
Operations
-->sayHello
. - Type your name in the (p0 String ) input text box and click the
sayHello
button.- For the
AnnotatedComponentHelloWorld
andMXComponentHelloWorld
examples, you will see a popup Window displayingHello <your name>!
. - For the
MXPojoHelloWorld
andSarMXPojoHelloWorld
examples, you will see a popup Window displayingWelcome <your name>!
.
- For the
-
Make sure you have started the JBoss EAP server as described above.
-
Open a command prompt and navigate to the root directory of this quickstart.
-
When you are finished testing, type this command to undeploy the archive:
mvn jboss-as:undeploy
You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see Use JBoss Developer Studio or Eclipse to Run the Quickstarts
If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them.
mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc