PageRenderTime 59ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/helloworld-mbean/README.md

https://gitlab.com/avinashmx/WildFly
Markdown | 133 lines | 84 code | 49 blank | 0 comment | 0 complexity | b5cf46d95c2db0e33526ec07a55c95d1 MD5 | raw file
  1. helloworld-mbean: Helloworld Using MBean and CDI component
  2. ======================================================
  3. Author: Lagarde Jeremie
  4. Level: Intermediate
  5. Technologies: CDI, JMX, MBean
  6. Summary: The `helloworld-mbean` quickstart demonstrates the use of *CDI* and *MBean* in WildFly and includes JConsole instructions and Arquillian tests.
  7. Target Product: WildFly
  8. Source: <https://github.com/wildfly/quickstart/>
  9. What is it?
  10. -----------
  11. The `helloworld-mbean` quickstart demonstrates the use of *CDI* and *MBean* in Red Hat JBoss Enterprise Application Platform. The project also includes a set of Arquillian tests for MBeans.
  12. The example is composed of the following MBeans:
  13. 1. `AnnotatedComponentHelloWorld`: This MBean is a managed bean with '@MXBean' annotation.
  14. 1. `MXComponentHelloWorld`: This MBean is a managed bean with 'MXBean' interface.
  15. 1. `MXPojoHelloWorld`: This MBean is a pojo using MXBean interface and declared in the `jboss-service.xml` file.
  16. 1. `SarMXPojoHelloWorld`: This MBean is a pojo using MXBean interface and declared in jboss-service.xml in SAR packaging.
  17. System requirements
  18. -------------------
  19. The application this project produces is designed to be run on Red Hat JBoss Enterprise Application Platform 7 or later.
  20. All you need to build this project is Java 8.0 (Java SDK 1.8) or later and Maven 3.1.1 or later. See [Configure Maven for WildFly 10](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/CONFIGURE_MAVEN_JBOSS_EAP7.md#configure-maven-to-build-and-deploy-the-quickstarts) to make sure you are configured correctly for testing the quickstarts.
  21. Use of WILDFLY_HOME
  22. ---------------
  23. 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](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/USE_OF_EAP7_HOME.md#use-of-eap_home-and-jboss_home-variables).
  24. Start the WildFly Server
  25. -------------------------
  26. 1. Open a command prompt and navigate to the root of the WildFly directory.
  27. 2. The following shows the command line to start the server:
  28. For Linux: WILDFLY_HOME/bin/standalone.sh
  29. For Windows: WILDFLY_HOME\bin\standalone.bat
  30. Build and Deploy the Quickstart
  31. -------------------------
  32. 1. Make sure you have started the WildFly server as described above.
  33. 2. Open a command propmt and navigate to the root directory of this quickstart.
  34. 3. Type this command to build and deploy the archive:
  35. mvn clean wildfly:deploy
  36. 4. This will deploy `helloworld-mbean-webapp\target\wildfly-helloworld-mbean-helloworld-mbean-webapp.war` and `helloworld-mbean-service\target\wildfly-helloworld-mbean-helloworld-mbean-service.sar` to the running instance of the server.
  37. Access and Test the MBeans
  38. --------------------------
  39. 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/wildfly-helloworld-mbean-helloworld-mbean-webapp/>, you will see a screen shot image of the JConsole application,
  40. The following sections describe how to use 'JConsole' to inspect and test the MBeans.
  41. Start JConsole
  42. --------------
  43. To connect to the WildFly server using JConsole, open a command prompt and type the following command :
  44. For Linux: JDK_HOME/bin/jconsole
  45. For Windows: JDK_HOME\bin\jconsole.exe
  46. Select the local `org.jboss.modules.Main` process and click `Connect`.
  47. ![MBeans in JConsole Connection](helloworld-mbean-webapp/src/main/webapp/jconsole_connection.png)
  48. A dialog displays with the warning "Secure connection failed. Retry insecurely?". Click `Insecure` to continue.
  49. Test the MBeans in JConsole
  50. ---------------------------
  51. You can use JConsole to inspect and use the MBeans :
  52. ![MBeans in JConsole](helloworld-mbean-webapp/src/main/webapp/jconsole.png)
  53. 1. Click on the MBeans tab.
  54. 2. Expand `quickstarts` in the left column of the console.
  55. 3. Under `quickstarts`, you see the 4 MBeans: `AnnotatedComponentHelloWorld`, `MXComponentHelloWorld`, `MXPojoHelloWorld`, and `SarMXPojoHelloWorld`
  56. 4. Expand each MBean and choose: `Operations` --> `sayHello`.
  57. 5. Type your name in the (p0 String ) input text box and click the `sayHello` button.
  58. * For the `AnnotatedComponentHelloWorld` and `MXComponentHelloWorld` examples, you will see a popup Window displaying `Hello <your name>!`.
  59. * For the `MXPojoHelloWorld` and `SarMXPojoHelloWorld` examples, you will see a popup Window displaying `Welcome <your name>!`.
  60. Undeploy the Archive
  61. --------------------
  62. 1. Make sure you have started the WildFly server as described above.
  63. 2. Open a command prompt and navigate to the root directory of this quickstart.
  64. 3. When you are finished testing, type this command to undeploy the archive:
  65. mvn wildfly:undeploy
  66. Run the Quickstart in Red Hat JBoss Developer Studio or Eclipse
  67. -------------------------------------
  68. You can also start the server and deploy the quickstarts or run the Arquillian tests 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](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/USE_JBDS.md#use-jboss-developer-studio-or-eclipse-to-run-the-quickstarts)
  69. 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.
  70. 1. When you import the `helloworld-mbean` quickstart into JBoss Developer Studio, you see the following warnings for the `wildfly-helloworld-mbean-webapp/src/main/webapp/META-INF/jboss-service.xml` and `/wildfly-helloworld-mbean-service/src/main/resources/META-INF/jboss-service.xml` files:
  71. No grammar constraints (DTD or XML Schema) referenced in the document.
  72. There is a known issue with the schema for the `jboss-service.xml` file that prevents successful validation. To prevent import errors, these files do not specify the schema location (http://www.jboss.org/schema/jbossas/jboss-service_7_0.xsd).
  73. 2. Install the JBoss Tools Maven Packaging Configurator
  74. * If the "JBoss Central" page is not showing, open it by choosing `Help` --> `JBoss Central`.
  75. * Click the `Software/Install` tab at the bottom of the `JBoss Central`.
  76. * Select the "JBoss Tools Maven Packaging Configurator" and click `Update/Install`.
  77. 3. Right click on the parent `wildfly-helloworld-mbean` parent project and choose `Maven` --> `Update Project...`. Select all projects and click `OK`.
  78. 4. Right-click on the `helloworld-mbean-helloworld-mbean-service` project and choose `Run As` --> `Run on Server`.
  79. 5. Right-click on the `helloworld-mbean-helloworld-mbean-webapp` project and choose `Run As` --> `Run on Server`.
  80. 6. [Start JConsole](#start-jconsole) and [Test the MBeans in JConsole](#test-the-mbeans-in-jconsole) as described above.
  81. Debug the Application
  82. ------------------------------------
  83. 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.
  84. mvn dependency:sources