The helloworld-mbean
quickstart demonstrates the use of CDI and MBean in WildFly and includes JConsole instructions and Arquillian tests.
What is it?
The helloworld-mbean
quickstart demonstrates the use of CDI and MBean in WildFly Application Server. The project also includes a set of Arquillian tests for MBeans.
The example is composed of the following MBeans.
MBean | Description |
---|---|
|
This MBean is a managed bean with |
|
This MBean is a managed bean with |
|
This MBean is a POJO using |
|
This MBean is a pojo using |
System Requirements
The application this project produces is designed to be run on WildFly Application Server 12 or later.
All you need to build this project is Java 8.0 (Java SDK 1.8) or later and Maven 3.3.1 or later. See Configure Maven to Build and Deploy the Quickstarts to make sure you are configured correctly for testing the quickstarts.
Use of WILDFLY_HOME
In the following instructions, replace WILDFLY_HOME
with the actual path to your WildFly installation. The installation path is described in detail here: Use of WILDFLY_HOME and JBOSS_HOME Variables.
Start the WildFly Standalone Server
-
Open a terminal and navigate to the root of the WildFly directory.
-
Start the WildFly server with the default profile by typing the following command.
$ WILDFLY_HOME/bin/standalone.sh
NoteFor Windows, use the WILDFLY_HOME\bin\standalone.bat
script.
Build and Deploy the Quickstart
-
Make sure you start the WildFly server as described above.
-
Open a terminal and navigate to the root directory of this quickstart.
-
Type the following command to build the artifacts.
$ mvn clean package wildfly:deploy
This deploys the helloworld-mbean/target/helloworld-mbean-service.war
to the running instance of the server.
You should see a message in the server log indicating that the archive deployed successfully.
This also deploys the helloworld-mbean-service/target/helloworld-mbean-service.sar
to the running instance of the server.
Access and Test the MBeans
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/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.
Start JConsole
-
To connect to the WildFly server using JConsole, open a terminal and type the following command, replacing JDK_HOME with the path to your JDK installation :
JDK_HOME/bin/jconsole
NoteFor Windows, type JDK_HOME\bin\jconsole.exe
. -
Select the local org.jboss.modules.Main process and click Connect.
-
A dialog displays with the warning:
Secure connection failed. Retry insecurely?
-
Click Insecure to continue.
Test the MBeans in JConsole
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, and SarMXPojoHelloWorld
-
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 and MXComponentHelloWorld examples, you will see a popup Window displaying Hello <your name>!.
-
For the MXPojoHelloWorld and SarMXPojoHelloWorld examples, you will see a popup Window displaying Welcome <your name>!.
-
Undeploy the Quickstart
When you are finished testing the quickstart, follow these steps to undeploy the archive.
-
Make sure you start the WildFly server as described above.
-
Open a terminal and navigate to the root directory of this quickstart.
-
Type this command to undeploy the archive:
$ mvn wildfly:undeploy
Run the Arquillian Tests
This quickstart provides Arquillian tests. By default, these tests are configured to be skipped since Arquillian tests require the use of a container.
Note
|
The Arquillian tests deploy the application, so make sure you undeploy the quickstart before you begin. |
Follow these steps to run the tests.
-
Start the WildFly server as described above.
-
Open a terminal and navigate to the root directory of this quickstart.
-
Type the following command to run the
verify
goal with thearq-remote
profile activated.$ mvn clean verify -Parq-remote
Note
|
You can also let Arquillian manage the WildFly server by using the |
Run the Quickstart in Red Hat JBoss Developer Studio or Eclipse
You can also start the server and deploy the quickstarts or run the Arquillian tests in Red Hat JBoss Developer Studio or from Eclipse using JBoss tools. For general information about how to import a quickstart, add a WildFly server, and build and deploy a quickstart, see Use JBoss Developer Studio or Eclipse to Run the Quickstarts.
This quickstart consists of multiple projects and requires installation of the JBoss Tools Maven Packaging Configurator
, so it deploys and runs differently in JBoss Developer Studio than the other quickstarts.
-
Install the JBoss Tools Maven Packaging Configurator
-
If the Red Hat Central page is not showing, open it by choosing Help → Red Hat Central.
-
Click the Software/Update tab at the bottom of the Red Hat Central.
-
Scroll down to the Maven section, select the JBoss Tools Maven Packaging Configurator and click Install/Update.
-
-
Right click on the parent helloworld-mbean parent project and choose Maven → Update Project…. Select all projects and click OK.
-
Right-click on the helloworld-mbean-service project and choose Run As → Run on Server.
-
Right-click on the helloworld-mbean-webapp project and choose Run As → Run on Server.
-
Start JConsole and Test the MBeans in JConsole as described above.
-
To undeploy the web application, right-click on the helloworld-mbean-wepapp project and choose Run As → Maven build. Enter
wildfly:undeploy
for the Goals and click Run. -
To undeploy the web service, right-click on the helloworld-mbean-service project and choose Run As → Maven build. Enter
wildfly:undeploy
for the Goals and click Run.
Debug the Application
If you want to debug the source code of any library in the project, run the following command to pull the source into your local repository. The IDE should then detect it.
$ mvn dependency:sources