Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 3. Developing and deploying Thorntail application
In addition to using an example, you can create new Thorntail applications from scratch and deploy them to OpenShift.
3.1. Creating an application from scratch Copier lienLien copié sur presse-papiers!
Creating a simple Thorntail–based application with a REST endpoint from scratch.
Prerequisites
- OpenJDK 8 or OpenJDK 11 installed
- Maven 3.5.0 installed
Procedure
Create a directory for the application and navigate to it:
mkdir myApp cd myApp
$ mkdir myApp $ cd myAppCopy to Clipboard Copied! Toggle word wrap Toggle overflow We recommend you start tracking the directory contents with Git. For more information, see Git tutorial.
In the directory, create a
pom.xmlfile with the following content.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a directory structure for your application:
mkdir -p src/main/java/com/example/rest
mkdir -p src/main/java/com/example/restCopy to Clipboard Copied! Toggle word wrap Toggle overflow In the
src/main/java/com/example/restdirectory, create the source files:HelloWorldEndpoint.javawith the class that serves the HTTP endpoint:Copy to Clipboard Copied! Toggle word wrap Toggle overflow RestApplication.javawith the application context:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Execute the application using Maven:
mvn thorntail:run
$ mvn thorntail:runCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Results
Accessing the http://localhost:8080/rest/hello URL in your browser should return the following message:
Hello from Thorntail!
Hello from Thorntail!
After finishing the procedure, there should be a directory on your hard drive with the following contents:
3.2. Deploying Thorntail application to OpenShift Copier lienLien copié sur presse-papiers!
To deploy your Thorntail application to OpenShift, configure the pom.xml file in your application and then use the Fabric8 Maven plugin. You can specify a Java image by replacing the fabric8.generator.from URL in the pom.xml file.
The images are available in the Red Hat Ecosystem Catalog.
<fabric8.generator.from>IMAGE_NAME</fabric8.generator.from>
<fabric8.generator.from>IMAGE_NAME</fabric8.generator.from>
For example, the Java image for RHEL 7 with OpenJDK 8 is specified as:
<fabric8.generator.from>registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:latest</fabric8.generator.from>
<fabric8.generator.from>registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:latest</fabric8.generator.from>
3.2.1. Supported Java images for Thorntail Copier lienLien copié sur presse-papiers!
Thorntail is certified and tested with various Java images that are available for different operating systems. For example, Java images are available for RHEL 7 and RHEL 8 with OpenJDK 8 or OpenJDK 11. Similar images are available on IBM Z.
You require Docker or podman authentication to access the RHEL 8 images in the Red Hat Ecosystem Catalog.
The following table lists the images supported by Thorntail for different architectures. It also provides links to the images available in the Red Hat Ecosystem Catalog. The image pages contain authentication procedures required to access the RHEL 8 images.
3.2.1.1. Images on x86_64 architecture Copier lienLien copié sur presse-papiers!
| OS | Java | Red Hat Ecosystem Catalog |
|---|---|---|
| RHEL 7 | OpenJDK 8 | |
| RHEL 7 | OpenJDK 11 | |
| RHEL 8 | OpenJDK 8 | |
| RHEL 8 | OpenJDK 11 |
The use of a RHEL 8-based container on a RHEL 7 host, for example with OpenShift 3 or OpenShift 4, has limited support. For more information, see the Red Hat Enterprise Linux Container Compatibility Matrix.
3.2.1.2. Images on s390x (IBM Z) architecture Copier lienLien copié sur presse-papiers!
| OS | Java | Red Hat Ecosystem Catalog |
|---|---|---|
| RHEL 8 | Eclipse OpenJ9 11 |
The use of a RHEL 8-based container on a RHEL 7 host, for example with OpenShift 3 or OpenShift 4, has limited support. For more information, see the Red Hat Enterprise Linux Container Compatibility Matrix.
3.2.2. Preparing Thorntail application for OpenShift deployment Copier lienLien copié sur presse-papiers!
For deploying your Thorntail application to OpenShift, it must contain:
-
Launcher profile information in the application’s
pom.xmlfile.
In the following procedure, a profile with Fabric8 Maven plugin is used for building and deploying the application to OpenShift.
Prerequisites
- Maven is installed.
- Docker or podman authentication into Red Hat Ecosystem Catalog to access RHEL 8 images.
Procedure
Add the following content to the
pom.xmlfile in the application root directory:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace the
fabric8.generator.fromproperty in thepom.xmlfile to specify relevant Java image based on your architecture.x86_64 architecture
RHEL 7 with OpenJDK 8
<fabric8.generator.from>registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:latest</fabric8.generator.from>
<fabric8.generator.from>registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:latest</fabric8.generator.from>Copy to Clipboard Copied! Toggle word wrap Toggle overflow RHEL 7 with OpenJDK 11
<fabric8.generator.from>registry.access.redhat.com/openjdk/openjdk-11-rhel7:latest</fabric8.generator.from>
<fabric8.generator.from>registry.access.redhat.com/openjdk/openjdk-11-rhel7:latest</fabric8.generator.from>Copy to Clipboard Copied! Toggle word wrap Toggle overflow RHEL 8 with OpenJDK 8
<fabric8.generator.from>registry.redhat.io/openjdk/openjdk-8-rhel8:latest</fabric8.generator.from>
<fabric8.generator.from>registry.redhat.io/openjdk/openjdk-8-rhel8:latest</fabric8.generator.from>Copy to Clipboard Copied! Toggle word wrap Toggle overflow RHEL 8 with OpenJDK 11
<fabric8.generator.from>registry.redhat.io/openjdk/openjdk-11-rhel8:latest</fabric8.generator.from>
<fabric8.generator.from>registry.redhat.io/openjdk/openjdk-11-rhel8:latest</fabric8.generator.from>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
s390x (IBM Z) architecture
RHEL 8 with Eclipse OpenJ9 11
<fabric8.generator.from>registry.access.redhat.com/openj9/openj9-11-rhel8:latest</fabric8.generator.from>
<fabric8.generator.from>registry.access.redhat.com/openj9/openj9-11-rhel8:latest</fabric8.generator.from>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.2.3. Deploying Thorntail application to OpenShift using Fabric8 Maven plugin Copier lienLien copié sur presse-papiers!
To deploy your Thorntail application to OpenShift, you must perform the following:
- Log in to your OpenShift instance.
- Deploy the application to the OpenShift instance.
Prerequisites
-
ocCLI client installed. - Maven installed.
Procedure
Log in to your OpenShift instance with the
occlient.oc login ...
$ oc login ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a new project in the OpenShift instance.
oc new-project MY_PROJECT_NAME
$ oc new-project MY_PROJECT_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the application to OpenShift using Maven from the application’s root directory. The root directory of an application contains the
pom.xmlfile.mvn clean fabric8:deploy -Popenshift
$ mvn clean fabric8:deploy -PopenshiftCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command uses the Fabric8 Maven Plugin to launch the S2I process on OpenShift and start the pod.
Verify the deployment.
Check the status of your application and ensure your pod is running.
oc get pods -w
$ oc get pods -w NAME READY STATUS RESTARTS AGE MY_APP_NAME-1-aaaaa 1/1 Running 0 58s MY_APP_NAME-s2i-1-build 0/1 Completed 0 2mCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
MY_APP_NAME-1-aaaaapod should have a status ofRunningonce it is fully deployed and started.Your specific pod name will vary.
Determine the route for the pod.
Example Route Information
oc get routes
$ oc get routes NAME HOST/PORT PATH SERVICES PORT TERMINATION MY_APP_NAME MY_APP_NAME-MY_PROJECT_NAME.OPENSHIFT_HOSTNAME MY_APP_NAME 8080Copy to Clipboard Copied! Toggle word wrap Toggle overflow The route information of a pod gives you the base URL which you use to access it.
In this example,
http://MY_APP_NAME-MY_PROJECT_NAME.OPENSHIFT_HOSTNAMEis the base URL to access the application.Verify that your application is running in OpenShift.
curl http://MY_APP_NAME-MY_PROJECT_NAME.OPENSHIFT_HOSTNAME/rest/hello
$ curl http://MY_APP_NAME-MY_PROJECT_NAME.OPENSHIFT_HOSTNAME/rest/hello Hello from Thorntail!Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.3. Deploying Thorntail application to stand-alone Red Hat Enterprise Linux Copier lienLien copié sur presse-papiers!
To deploy your Thorntail application to stand-alone Red Hat Enterprise Linux, configure the pom.xml file in the application, package it using Maven and deploy using the java -jar command.
Prerequisites
- RHEL 7 or RHEL 8 installed.
3.3.1. Preparing Thorntail application for stand-alone Red Hat Enterprise Linux deployment Copier lienLien copié sur presse-papiers!
For deploying your Thorntail application to stand-alone Red Hat Enterprise Linux, you must first package the application using Maven.
Prerequisites
- Maven installed.
Procedure
Add the following content to the
pom.xmlfile in the application’s root directory:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Package your application using Maven.
mvn clean package
$ mvn clean packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow The resulting JAR file is in the
targetdirectory.
3.3.2. Deploying Thorntail application to stand-alone Red Hat Enterprise Linux using jar Copier lienLien copié sur presse-papiers!
To deploy your Thorntail application to stand-alone Red Hat Enterprise Linux, use java -jar command.
Prerequisites
- RHEL 7 or RHEL 8 installed.
- OpenJDK 8 or OpenJDK 11 installed.
- A JAR file with the application.
Procedure
Deploy the JAR file with the application.
java -jar my-app-thorntail.jar
$ java -jar my-app-thorntail.jarCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the deployment.
Use
curlor your browser to verify your application is running athttp://localhost:8080:curl http://localhost:8080
$ curl http://localhost:8080Copy to Clipboard Copied! Toggle word wrap Toggle overflow