Chapter 3. Deploying an application to the server

You can deploy your application on a JBoss EAP server running on bare metal or on OpenShift Container Platform.

To deploy your application on a JBoss EAP server running on bare metal, follow this procedure:

To deploy your application on a JBoss EAP server running on OpenShift Container Platform, follow these procedures:

3.1. Deploying an application to a bare metal installation

You can deploy an application to JBoss EAP by using the JBoss EAP deploy plug-in.

Prerequisites

Procedure

  1. Navigate to the application root directory.

    The application root directory contains the pom.xml configuration file.

  2. Add the following build configuration to the pom.xml configuration file in the <project> section to define the application archive filename.

    <build>
        ...
        <finalName>${project.artifactId}</finalName>        1
    </build>
    1
    Set the name of the deployment to the project’s artifact ID.
  3. Build and deploy the application by using the JBoss EAP deploy plug-in.

    $ mvn package wildfly:deploy

Verification

3.2. Deploying an application to OpenShift Container Platform

You can use the source-to-image (S2I) workflow to deploy your applications to JBoss EAP on OpenShift Container Platform. The S2I workflow takes source code from a Git repository and injects it into a container that’s based on the language and framework you want to use. After the S2I workflow is completed, the src code is compiled, the application is packaged and is deployed to the JBoss EAP server.

3.2.1. Preparing an application for deployment on OpenShift Container Platform

OpenShift Container Platform uses application hosted on a Git repository. To deploy your application on OpenShift, you must first push your application to a Git repository. After that, you can use JBoss EAP helm chart to configure your application deployment.

Prerequisites

Procedure

  1. Move the application to your local Git repository, if it already is not in it.

    $ mv -r helloworld/ <your_git_repo>
  2. Define the following property in the pom.xml configuration file:

    <properties>
        ...
        <version.plugin.eap>1.0.0.Final-redhat-00013</version.plugin.eap> 1
    </properties>
    1
    <version.plugin.eap> defines the version for JBoss EAP Maven plug-in.
  3. Add the JBoss EAP maven plugin to <pluginManagement>, in <build> section inside the <project> section.

    <project>
        ...
        <build>
            <pluginManagement>
                <plugins>
                    ...
                    <plugin>
                        <groupId>org.jboss.eap.plugins</groupId>
                        <artifactId>eap-maven-plugin</artifactId>
                        <version>${version.plugin.eap}</version>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </project>
  4. Create a profile "openshift" in the pom.xml configuration file.

    This profile defines the plug-ins, feature packs, and layers required for deployment on OpenShift Container Platform.

    <profiles>
        <profile>
            <id>openshift</id>
            <build>
                <plugins>
                    <plugin>
                         <groupId>org.jboss.eap.plugins</groupId>
                         <artifactId>eap-maven-plugin</artifactId>     1
                         <configuration>
                             <channels>
                                 <channel>
                                     <manifest>
                                         <groupId>org.jboss.eap.channels</groupId>
                                         <artifactId>eap-8.0</artifactId>
                                     </manifest>
                                 </channel>
                             </channels>
                             <feature-packs>
                                 <feature-pack>                            2
                                     <location>org.jboss.eap:wildfly-ee-galleon-pack</location>
                                 </feature-pack>
                                 <feature-pack>
                                     <location>org.jboss.eap.cloud:eap-cloud-galleon-pack</location>
                                 </feature-pack>
                             </feature-packs>
                             <layers>                                      3
                                 <layer>cloud-server</layer>
                             </layers>
                             <name>ROOT.war</name>                         4
                         </configuration>
                         <executions>
                             <execution>
                                 <goals>
                                     <goal>package</goal>
                                 </goals>
                             </execution>
                         </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    1
    wildfly-maven-plugin is a JBoss EAP plug-in for provisioning a JBoss EAP instance, with the application deployed, on OpenShift Container Platform.
    2
    feature-packs defines the feature-packs (zipped files that contains features to dynamically provision a server). In this case we need the feature-packs org.wildfly:wildfly-galleon-pack and org.wildfly.cloud:wildfly-cloud-galleon-pack.
    3
    layers defines the layers (from the configured feature-packs) to include in the provisioned server. Each layer identifies one or more server capabilities that can be installed on its own, or in combination with other layers. In our case we opt for the cloud-server layer, which provisions just the basic features of JBoss EAP, well suited for a cloud server.
    4
    <name>ROOT.war</name>: Defines the resulting name of the application’s web archive (WAR). If ROOT.war is specified then the application is deployed at the root path of the server, otherwise it is deployed at <name/> relative path.
  5. Verify that the applications compiles.

    $ mvn package -Popenshift
  6. Push the changes to your repository.

3.2.2. Deploying an application to JBoss EAP on OpenShift with Helm

Use the JBoss EAP Helm chart to configure and deploy application to JBoss EAP on OpenShift with Helm.

Prerequisites

Procedure

  1. Create a directory called charts in the application root directoy and navigate to it. Application root directory is the one that contains pom.xml configuration file.

    $ mkdir charts; cd charts
  2. Create a file helm.yaml with the following content:

    build:
      uri: https://github.com/<user>/<repository>.git     1
      ref: <branch_name>                                  2
      contextDir: helloworld                              3
    deploy:
      replicas: 1                                         4
    1
    Specify the URL for your Git repository that contains the application to deploy on OpenShift Container Platform.
    2
    Specify the Git branch that contains your application.
    3
    Specify the directory containing the application.
    4
    Specify the number of pods to create.
  3. Configure the JBoss EAP repository in Helm.

    • If you haven’t added the JBoss EAP repository to Helm before, add it.

      $ helm repo add jboss-eap https://jbossas.github.io/eap-charts/
    • If you already have added the JBoss EAP repository to Helm, update it.

      $ helm repo update jboss-eap
  4. Deploy the application using helm.

    $ helm install helloworld -f helm.yaml jboss-eap/eap8

    The deployment can take a few minutes to complete.

Verification

  1. Get the URL of the route to the deployment.

    $ APPLICATION_URL=https://$(oc get route helloworld --template='{{ .spec.host }}') &&
    echo "" &&
    echo "Application URL: $APPLICATION_URL"
  2. Navigate to the "Application URL" in a browser.

    You are redirected to the servlet at path "/HelloWorld" and you get the following message:

    Hello World!