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 Copy linkLink copied to clipboard!
You can deploy an application to JBoss EAP by using the JBoss EAP deploy plug-in.
Prerequisites
You have created an application.
For more information, see Creating a hello world servlet.
- JBoss EAP is running.
Procedure
Navigate to the application root directory.
The application root directory contains the
pom.xmlconfiguration file.Add the following build configuration to the
pom.xmlconfiguration 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.
Build and deploy the application by using the JBoss EAP deploy plug-in.
$ mvn package wildfly:deploy
Verification
Navigate to the address
http://localhost:8080/helloworld/in a browser.You are redirected to http://localhost:8080/helloworld/HelloWorld and you get the following message:
Hello World!
3.2. Deploying an application to OpenShift Container Platform Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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
You have created an application.
For more information, see Creating a Hello World servlet.
- You have created a Git repository.
Procedure
Move the application to your local Git repository, if it already is not in it.
$ mv -r helloworld/ <your_git_repo>Define the following property in the
pom.xmlconfiguration 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.
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>Create a profile "openshift" in the
pom.xmlconfiguration 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-pluginis a JBoss EAP plug-in for provisioning a JBoss EAP instance, with the application deployed, on OpenShift Container Platform.- 2
feature-packsdefines the feature-packs (zipped files that contains features to dynamically provision a server). In this case we need the feature-packsorg.wildfly:wildfly-galleon-packandorg.wildfly.cloud:wildfly-cloud-galleon-pack.- 3
layersdefines 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 thecloud-serverlayer, 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). IfROOT.waris specified then the application is deployed at the root path of the server, otherwise it is deployed at<name/>relative path.
Verify that the applications compiles.
$ mvn package -Popenshift- Push the changes to your repository.
3.2.2. Deploying an application to JBoss EAP on OpenShift with Helm Copy linkLink copied to clipboard!
Use the JBoss EAP Helm chart to configure and deploy application to JBoss EAP on OpenShift with Helm.
Prerequisites
You have prepared your application for deployment on OpenShift Container Platform.
For more information, see Preparing an application for deployment on OpenShift Container Platform.
You have created a project in OpenShift Container Platform.
For more information see Working with projects.
You have installed OpenShift CLI (
oc)For more information, see Installing the OpenShift CLI.
You are logged in to OpenShift Container Platform from your machine.
For more information, see Logging in to the OpenShift CLI.
You have installed helm.
For more information, see Installing Helm.
Procedure
Create a directory called
chartsin the application root directoy and navigate to it. Application root directory is the one that containspom.xmlconfiguration file.$ mkdir charts; cd chartsCreate a file
helm.yamlwith the following content:build: uri: https://github.com/<user>/<repository>.git1 ref: <branch_name>2 contextDir: helloworld3 deploy: replicas: 14 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
Deploy the application using helm.
$ helm install helloworld -f helm.yaml jboss-eap/eap8The deployment can take a few minutes to complete.
Verification
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"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!