Red Hat Training

A Red Hat training course is available for Red Hat JBoss Enterprise Application Platform

Chapter 3. Developing Applications Using JBoss EAP

3.1. Overview

This guide provides information on getting started developing applications by using Red Hat JBoss Developer Studio and the JBoss EAP 7 quickstart examples.

Red Hat JBoss Developer Studio is an Eclipse-based integrated development environment (IDE) that integrates JBoss application development plug-ins. JBoss Developer Studio can assist with your application development with the availability of JBoss-specific wizards and the ability to deploy applications to JBoss EAP servers. Many quickstart code examples are provided with JBoss EAP 7 to help users get started writing applications using different Java EE 7 technologies.

This guide provides basic installation instructions for JBoss Developer Studio. See the Install Red Hat JBoss Developer Studio guide for complete installation instructions.

3.2. Setting up the Development Environment

3.2.1. Download JBoss Developer Studio

JBoss Developer Studio can be downloaded from the Red Hat Customer Portal.

  1. Log in to the Red Hat Customer Portal.
  2. Click Downloads.
  3. In the Product Downloads list, click Red Hat JBoss Developer Studio.
  4. Select the desired version in the Version drop-down menu.

    Note

    It is recommended to use JBoss Developer Studio version 9.1 or later.

  5. Find the Red Hat JBoss Developer Studio 9.x.x Stand-alone Installer entry in the table and click Download.
  6. Save the JAR file to the desired directory.

3.2.2. Install JBoss Developer Studio

  1. Open a terminal and navigate to the directory containing the downloaded JAR file.
  2. Run the following command to launch the GUI installation program:

    $ java -jar jboss-devstudio-BUILD_VERSION-installer-standalone.jar
    Note

    Alternatively, you may be able to double-click the JAR file to launch the installation program.

  3. Click Next to start the installation process.
  4. Select I accept the terms of this license agreement and click Next.
  5. Adjust the installation path and click Next.

    Note

    If the installation path folder does not exist, a prompt will appear. Click OK to create the folder.

  6. Choose a JVM, or leave the default JVM selected, and click Next.
  7. Click Next when asked to select platforms and servers.
  8. Review the installation details, and click Next.
  9. Click Next when the installation process is complete.
  10. Configure the desktop shortcuts for JBoss Developer Studio, and click Next.
  11. Click Done.

3.2.3. Start JBoss Developer Studio

To start JBoss Developer Studio, you can double-click on the desktop shortcut created during the installation, or you can start it from a command line. Follow the below steps to start JBoss Developer Studio using the command line.

  1. Open a terminal and navigate to the JBoss Developer Studio installation directory.
  2. Run the following command to start JBoss Developer Studio:

    $ ./jbdevstudio
    Note

    For Windows Server, use the jbdevstudio.bat file.

3.2.4. Add the JBoss EAP Server to JBoss Developer Studio

These instructions assume that you have not yet added any JBoss EAP servers to JBoss Developer Studio. Use the following steps to add your JBoss EAP server using the Define New Server wizard.

  1. Open the Servers tab.

    Note

    If the Servers tab is not shown, add it to the panel by selecting WindowShow ViewServers.

  2. Click on the No servers are available. Click this link to create a new server link.

    Figure 3.1. Add a New Server

    The *Servers* tab when no servers are available.
  3. Expand Red Hat JBoss Middleware and choose JBoss Enterprise Application Platform 7.0. Enter a server name, for example, JBoss EAP 7.0, then click Next.

    Figure 3.2. Define a New Server

    The *Define a New Server* window.
  4. Create a server adapter to manage starting and stopping the server. Keep the defaults and click Next.

    Figure 3.3. Create a New Server Adapter

    The *Create a New Server Adapter* window.
  5. Enter a name, for example JBoss EAP 7.0 Runtime. Click Browse next to Home Directory and navigate to your JBoss EAP installation directory. Then click Next.

    Figure 3.4. Add New Server Runtime Environment

    The *JBoss Runtime* window.
    Note

    Some quickstarts require that you run the server with a different profile or additional arguments. For example, to deploy a quickstart that requires the full profile, you must define a new server and specify standalone-full.xml in the Configuration file field. Be sure to give the new server a descriptive name.

  6. Configure existing projects for the new server. Because you do not have any projects at this point, click Finish.

    Figure 3.5. Modify Resources for the New Server

    The *Add and Remove Resources* window.

The JBoss EAP 7.0 server is now listed in the Servers tab.

Figure 3.6. Server List

The *Servers* tab when the `JBoss EAP 7.0` server is listed.

3.3. Using the Quickstart Examples

The quickstart examples provided with JBoss EAP are Maven projects.

3.3.1. About Maven

Apache Maven is a distributed build automation tool used in Java application development to create, manage, and build software projects. Maven uses standard configuration files called Project Object Model (POM) files to define projects and manage the build process. POMs describe the module and component dependencies, build order, and targets for the resulting project packaging and output using an XML file. This ensures that the project is built in a correct and uniform manner.

Maven achieves this by using a repository. A Maven repository stores Java libraries, plug-ins, and other build artifacts. The default public repository is the Maven 2 Central Repository, but repositories can be private and internal within a company with a goal to share common artifacts among development teams. Repositories are also available from third-parties. For more information, see the Apache Maven project and the Introduction to Repositories guide.

JBoss EAP includes a Maven repository that contains many of the requirements that Java EE developers typically use to build applications on JBoss EAP.

For more information about how to use Maven with JBoss EAP, see Using Maven with JBoss EAP in the JBoss EAP Development Guide.

3.3.2. Using Maven with the Quickstarts

The artifacts and dependencies needed to build and deploy applications to JBoss EAP 7 are hosted on a public repository. Starting with the JBoss EAP 7 quickstarts, it is no longer necessary to configure your Maven settings.xml file to use these repositories when building the quickstarts. The Maven repositories are now configured in the quickstart project POM files. This method of configuration is provided to make it easier to get started with the quickstarts, however, is generally not recommended for production projects because it can slow down your build.

Red Hat JBoss Developer Studio includes Maven, so there is no need to download and install it separately. It is recommended to use JBoss Developer Studio version 9.1 or later.

If you plan to use the Maven command line to build and deploy your applications, then you must first download Maven from the Apache Maven project and install it using the instructions provided in the Maven documentation.

3.3.3. Download and Run the Quickstarts

3.3.3.1. Download the Quickstarts

JBoss EAP comes with a comprehensive set of quickstart code examples designed to help users begin writing applications using various Java EE 7 technologies. The quickstarts can be downloaded from the Red Hat Customer Portal.

  1. Log in to the Red Hat Customer Portal.
  2. Click Downloads.
  3. In the Product Downloads list, click Red Hat JBoss Enterprise Application Platform.
  4. Select the desired version in the Version drop-down menu.
  5. Find the Red Hat JBoss Enterprise Application Platform 7.0.0 Quickstarts entry in the table and click Download.
  6. Save the ZIP file to the desired directory.
  7. Extract the ZIP file.

3.3.3.2. Run the Quickstarts in JBoss Developer Studio

Once the quickstarts have been downloaded, they can be imported into JBoss Developer Studio and deployed to JBoss EAP.

Import a Quickstart into JBoss Developer Studio

Each quickstart ships with a POM file that contains its project and configuration information. Use this POM file to easily import the quickstart into JBoss Developer Studio.

Important

If your quickstart project folder is located within the IDE workspace when you import it into JBoss Developer Studio, the IDE generates an invalid project name and WAR archive name. Be sure your quickstart project folder is located outside the IDE workspace before you begin.

  1. Start JBoss Developer Studio.
  2. Select FileImport.
  3. Choose MavenExisting Maven Projects, then click Next.

    Figure 3.7. Import Existing Maven Projects

    The *Import* window.
  4. Browse to the desired quickstart’s directory (for example the helloworld quickstart), and click OK. The Projects list box is populated with the pom.xml file of the selected quickstart project.

    Figure 3.8. Select Maven Projects

    The *Maven Projects* selection window.
  5. Click Finish.

Run the helloworld Quickstart

Running the helloworld quickstart is a simple way to verify that the JBoss EAP server is configured and running correctly.

  1. If you have not yet defined a server, add the JBoss EAP server to JBoss Developer Studio.
  2. Right-click the jboss-helloworld project in the Project Explorer tab and select Run AsRun on Server.

    Figure 3.9. Run As - Run on Server

    The *Run As* -> *Run on Server* screen capture.
  3. Select JBoss EAP 7.0 from the server list and click Next.

    Figure 3.10. Run on Server

    The *Run on Server* window.
  4. The jboss-helloworld quickstart is already listed to be configured on the server. Click Finish to deploy the quickstart.

    Figure 3.11. Modify Resources Configured on the Server

    The *Add and Remove Resources* window.
  5. Verify the results.

    • In the Server tab, the JBoss EAP 7.0 server status changes to Started .
    • The Console tab shows messages detailing the JBoss EAP server start and the helloworld quickstart deployment.

      WFLYUT0021: Registered web context: /jboss-helloworld
      WFLYSRV0010: Deployed "jboss-helloworld.war" (runtime-name : "jboss-helloworld.war")
    • The helloworld application is available at http://localhost:8080/jboss-helloworld and displays the text Hello World!.

Run the bean-validation Quickstart

Some quickstarts, such as the bean-validation quickstart, do not provide a user interface layer and instead provide Arquillian tests to demonstrate functionality.

  1. Import the bean-validation quickstart into JBoss Developer Studio.
  2. In the Servers tab, right-click on the server and choose Start to start the JBoss EAP server. If you do not see a Servers tab or have not yet defined a server, add the JBoss EAP server to Red Hat JBoss Developer Studio.
  3. Right-click on the jboss-bean-validation project in the Project Explorer tab and select Run AsMaven Build.
  4. Enter the following in the Goals input field and then click Run.

    clean test -Parq-wildfly-remote

    Figure 3.12. Edit Configuration

    The *Edit Configuration* window.
  5. Verify the results.

    The Console tab shows the results of the bean-validation Arquillian tests:

    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running org.jboss.as.quickstarts.bean_validation.test.MemberValidationTest
    Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.189 sec
    
    Results :
    
    Tests run: 5, Failures: 0, Errors: 0, Skipped: 0
    
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------

3.3.3.3. Run the Quickstarts from the Command Line

You can easily build and deploy the quickstarts from the command line using Maven. If you do not yet have Maven installed, see the Apache Maven project to download and install it.

A README.md file is provided at the root directory of the quickstarts that contains general information about system requirements, configuring Maven, adding users, and running the quickstarts.

Each quickstart also contains its own README.md file that provides the specific instructions and Maven commands to run that quickstart.

Run the helloworld Quickstart from the Command Line

  1. Review the README.md file in the root directory of the helloworld quickstart.
  2. Start the JBoss EAP server.

    $ EAP_HOME/bin/standalone.sh
  3. Navigate to the helloworld quickstart directory.
  4. Build and deploy the quickstart using the Maven command provided in the quickstart’s README.md file.

    mvn clean install wildfly:deploy
  5. The helloworld application is now available at http://localhost:8080/jboss-helloworld and displays the text Hello World!.