Chapter 2. Getting started with Red Hat JBoss Web Server for OpenShift


You can import the latest Red Hat JBoss Web Server for OpenShift image streams and templates from the Red Hat container registry. You can subsequently use the JWS for OpenShift Source-to-Image (S2I) process to create JBoss Web Server for OpenShift applications by using existing maven binaries or from source code.

Before you follow the instructions in this document, you must ensure that an OpenShift cluster is already installed and configured as a prerequisite. For more information about installing and configuring OpenShift clusters, see the OpenShift Container Platform Installing guide.

Note

The JWS for OpenShift application templates are distributed for Tomcat 10.

2.1. Configuring an authentication token for the Red Hat Container Registry

Before you can import and use a Red Hat JBoss Web Server for OpenShift image, you must first ensure that you have configured an authentication token to access the Red Hat Container Registry.

You can create an authentication token by using a registry service account. This means that you do not have to use or store your Red Hat account username and password in your OpenShift configuration.

Procedure

  1. Follow the instructions on the Red Hat Customer Portal to create an authentication token using a registry service account.
  2. On the Token Information page for your token, click the OpenShift Secret tab and download the YAML file that contains the OpenShift secret for the token.
  3. Use the YAML file that you have downloaded to create the authentication token secret for your OpenShift project.

    For example:

    Copy to Clipboard Toggle word wrap
    oc create -f 1234567_myserviceaccount-secret.yaml
  4. To configure the secret for your OpenShift project, enter the following commands:

    Copy to Clipboard Toggle word wrap
    oc secrets link default 1234567-myserviceaccount-pull-secret --for=pull
    oc secrets link builder 1234567-myserviceaccount-pull-secret --for=pull
    Note

    In the preceding examples, replace 1234567-myserviceaccount with the name of the secret that you created in the previous step.

2.2. Importing JBoss Web Server image streams and templates

You can import Red Hat JBoss Web Server for OpenShift image streams and templates from the Red Hat Container Registry. You must import the latest JBoss Web Server image streams and templates for your JDK into the namespace of your OpenShift project.

Procedure

  1. Log in to the Red Hat Container Registry by using your Customer Portal credentials. For more information, see Red Hat Container Registry Authentication.
  2. Depending on the JDK version that you are using, perform one of the following steps:

    • OpenJDK 17

      If you are using OpenJDK 17, enter the following command:

      Copy to Clipboard Toggle word wrap
      for resource in \
      jws61-openjdk17-tomcat10-ubi8-basic-s2i.json \
      jws61-openjdk17-tomcat10-ubi8-https-s2i.json \
      jws61-openjdk17-tomcat10-ubi8-image-stream.json
      do
      oc replace -n openshift --force -f \
      https://raw.githubusercontent.com/jboss-container-images/jboss-webserver-6-openshift-image/jws61el8-v6.1.0/templates/${resource}
      done

      The preceding command imports the UBI8 JDK 17 image stream, jboss-webserver61-openjdk17-tomcat10-openshift-ubi8, and all templates specified in the command.

    • OpenJDK 21

      If you are using OpenJDK 21, enter the following command:

      Copy to Clipboard Toggle word wrap
      for resource in \
      jws61-openjdk21-tomcat10-ubi8-basic-s2i.json \
      jws61-openjdk21-tomcat10-ubi8-https-s2i.json \
      jws61-openjdk21-tomcat10-ubi8-image-stream.json
      do
      oc replace -n openshift --force -f \
      https://raw.githubusercontent.com/jboss-container-images/jboss-webserver-6-openshift-image/jws61el8-v6.1.0/templates/${resource}
      done

      The preceding command imports the UBI8 JDK 21 image stream, jboss-webserver61-openjdk21-tomcat10-openshift-ubi8, and all templates specified in the command.

2.3. Importing the latest JWS for OpenShift image

You can import the latest available JWS for OpenShift image by using the import-image command. Red Hat provides separate JWS for OpenShift images for OpenJDK 17 and OpenJDK 21.

Procedure

  • Depending on the JDK version that you are using, perform one of the following steps:

    • To update the core JBoss Web Server 6.1 tomcat 10 with OpenJDK 17 OpenShift image, enter the following command:

      Copy to Clipboard Toggle word wrap
      $ oc -n openshift import-image \
        jboss-webserver61-openjdk17-tomcat10-openshift-ubi8:6.1.0
    • To update the core JBoss Web Server 6.1 tomcat 10 with OpenJDK 21 OpenShift image, enter the following command:

      Copy to Clipboard Toggle word wrap
      $ oc -n openshift import-image \
        jboss-webserver61-openjdk21-tomcat10-openshift-ubi8:6.1.0
Note

The 6.1.0 tag at the end of each image you import refers to the stream version that is set in the OpenJDK 17 image stream or OpenJDK 21 image stream.

2.4. JWS for OpenShift S2I process

You can run and configure the JWS for OpenShift images by using the OpenShift source-to-image (S2I) process with the application template parameters and environment variables.

The S2I process for the JWS for OpenShift images works as follows:

  • If the configuration source directory contains a Maven settings.xml file, the settings.xml file is moved to the $HOME/.m2/ directory of the new image.
  • If the source repository contains a pom.xml file, a Maven build is triggered using the contents of the $MAVEN_ARGS environment variable.

    By default, the package goal is used with the openshift profile, which includes the -DskipTests argument to skip tests, and the -Dcom.redhat.xpaas.repo.redhatga argument to enable the Red Hat GA repository.

  • The results of a successful Maven build are copied to the /opt/jws-6.1/tomcat/webapps directory. This includes all WAR files from the source directory that is specified by the $ARTIFACT_DIR environment variable. The default value of $ARTIFACT_DIR is the target/ directory.

    You can use the $MAVEN_ARGS_APPEND environment variable to modify the Maven arguments.

  • All WAR files from the deployments source directory are copied to the /opt/jws-6.1/tomcat/webapps directory.
  • All files in the configuration source directory are copied to the /opt/jws-6.1/tomcat/conf/ directory, excluding the Maven settings.xml file.
  • All files in the lib source directory are copied to the /opt/jws-6.1/tomcat/lib/ directory.

    Note

    If you want to use custom Tomcat configuration files, use the same file names that are used for a normal Tomcat installation such as context.xml and server.xml.

For more information about configuring the S2I process to use a custom Maven artifacts repository mirror, see Maven artifact repository mirrors and JWS for OpenShift.

Additional resources

2.5. Creating a JWS for OpenShift application by using existing Maven binaries

You can create a JWS for OpenShift application by using existing Maven binaries. You can use the oc start-build command to deploy existing applications on OpenShift.

Note

This procedure shows how to create an example application that is based on the tomcat-websocket-chat quickstart example.

Prerequisites

  • You have an existing .war, .ear, or .jar file for the application that you want to deploy on JWS for OpenShift or you have built the application locally.

    For example, to build the tomcat-websocket-chat application locally, perform the following steps:

    1. To clone the source code, enter the following command:

      Copy to Clipboard Toggle word wrap
      $ git clone https://github.com/web-servers/tomcat-websocket-chat-quickstart.git
    2. Configure the Red Hat JBoss Middleware Maven repository, as described in Configure the Red Hat JBoss Middleware Maven Repository.

      For more information about the Maven repository, see the Red Hat JBoss Enerprise Maven Repository web page.

    3. To build the application, enter the following commands:

      Copy to Clipboard Toggle word wrap
      $ cd tomcat-websocket-chat-quickstart/tomcat-websocket-chat/
      $ mvn clean package

      The preceding command produces the following output:

      Copy to Clipboard Toggle word wrap
      [INFO] Scanning for projects...
      [INFO]
      [INFO] ------------------------------------------------------------------------
      [INFO] Building Tomcat websocket example 1.2.0.Final
      [INFO] ------------------------------------------------------------------------
      ...
      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD SUCCESS
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 01:28 min
      [INFO] Finished at: 2018-01-16T15:59:16+10:00
      [INFO] Final Memory: 19M/271M
      [INFO] ------------------------------------------------------------------------

Procedure

  1. On your local file system, create a source directory for the binary build and a deployments subdirectory.

    For example, to create a /ocp source directory and a /deployments subdirectory for the tomcat-websocket-chat application, enter the following commands:

    Copy to Clipboard Toggle word wrap
    $ cd tomcat-websocket-chat-quickstart/tomcat-websocket-chat/
    $ mkdir -p ocp/deployments
    Note

    The source directory can contain any content required by your application that is not included in the Maven binary. For more information, see JWS for OpenShift S2I process.

  2. Copy the .war,.ear, or .jar binary files to the deployments subdirectory.

    For example, to copy the .war file for the example tomcat-websocket-chat application, enter the following command:

    Copy to Clipboard Toggle word wrap
    $ cp target/websocket-chat.war ocp/deployments/
    Note

    In the preceding example, target/websocket-chat.war is the path to the binary file you want to copy.

    Application archives in the deployments subdirectory of the source directory are copied to the $JWS_HOME/tomcat/webapps/ directory of the image that is being built on OpenShift. To allow the application to be deployed successfully, you must ensure that the directory hierarchy that contains the web application data is structured correctly. For more information, see JWS for OpenShift S2I process.

  3. Log in to the OpenShift instance:

    Copy to Clipboard Toggle word wrap
    $ oc login <url>
  4. Create a new project if required.

    For example:

    Copy to Clipboard Toggle word wrap
    $ oc new-project jws-bin-demo
    Note

    In the preceding example, jws-bin-demo is the name of the project you want to create.

  5. Identify the JWS for OpenShift image stream to use for your application:

    Copy to Clipboard Toggle word wrap
    $ oc get is -n openshift | grep ^jboss-webserver | cut -f1 -d ' '

    The preceding command produces the following type of output:

    Copy to Clipboard Toggle word wrap
    jboss-webserver61-openjdk17-tomcat10-openshift-ubi8
    Note

    The -n openshift option specifies the project to use. The oc get is -n openshift command gets the image stream resources from the openshift project.

  6. Create the new build configuration, and ensure that you specify the image stream and application name.

    For example, to create the new build configuration for the example tomcat-websocket-chat application:

    Copy to Clipboard Toggle word wrap
    $ oc new-build --binary=true \
     --image-stream=jboss-webserver61-openjdk17-tomcat10-openshift-ubi8:latest \
     --name=jws-wsch-app
    Note

    In the preceding example, jws-wsch-app is the name of the JWS for OpenShift application.

    The preceding command produces the following type of output:

    Copy to Clipboard Toggle word wrap
    --> Found image 8c3b85b (4 weeks old) in image stream "openshift/jboss-webserver61-tomcat10-openshift" under tag "latest" for "jboss-webserver61"
    
        JBoss Web Server 6.1
        --------------------
        Platform for building and running web applications on JBoss Web Server 6.1 - Tomcat v10
    
        Tags: builder, java, tomcat10
    
        * A source build using binary input will be created
          * The resulting image will be pushed to image stream "jws-wsch-app:latest"
          * A binary build was created, use 'start-build --from-dir' to trigger a new build
    
    --> Creating resources with label build=jws-wsch-app ...
        imagestream "jws-wsch-app" created
        buildconfig "jws-wsch-app" created
    --> Success
  7. Start the binary build.

    For example:

    Copy to Clipboard Toggle word wrap
    $ oc start-build jws-wsch-app --from-dir=./ocp --follow
    Note

    In the preceding example, jws-wsch-app is the name of the JWS for OpenShift application, and ocp is the name of the source directory.

    The preceding command instructs OpenShift to use the source directory that you have created for binary input of the OpenShift image build.

    The preceding command produces the following type of output:

    Copy to Clipboard Toggle word wrap
    Uploading directory "ocp" as binary input for the build ...
    build "jws-wsch-app-1" started
    Receiving source from STDIN as archive ...
    
    Copying all deployments war artifacts from /home/jboss/source/deployments directory into `/opt/jws-6.1/tomcat/webapps` for later deployment...
    '/home/jboss/source/deployments/websocket-chat.war' -> '/opt/jws-6.1/tomcat/webapps/websocket-chat.war'
    
    Pushing image 172.30.202.111:5000/jws-bin-demo/jws-wsch-app:latest ...
    Pushed 0/7 layers, 7% complete
    Pushed 1/7 layers, 14% complete
    Pushed 2/7 layers, 29% complete
    Pushed 3/7 layers, 49% complete
    Pushed 4/7 layers, 62% complete
    Pushed 5/7 layers, 92% complete
    Pushed 6/7 layers, 100% complete
    Pushed 7/7 layers, 100% complete
    Push successful
  8. Create a new OpenShift application based on the image:

    For example:

    Copy to Clipboard Toggle word wrap
    $ oc new-app jws-wsch-app
    Note

    In the preceding example, jws-wsch-app is the name of the JWS for OpenShift application.

    The preceding command produces the following type of output:

    Copy to Clipboard Toggle word wrap
    --> Found image e5f3a6b (About a minute old) in image stream "jws-bin-demo/jws-wsch-app" under tag "latest" for "jws-wsch-app"
    
        JBoss Web Server 6.1
        --------------------
        Platform for building and running web applications on JBoss Web Server 6.1 - Tomcat v10
    
        Tags: builder, java, tomcat10
    
        * This image will be deployed in deployment config "jws-wsch-app"
        * Ports 8080/tcp, 8443/tcp, 8778/tcp will be load balanced by service "jws-wsch-app"
          * Other containers can access this service through the hostname "jws-wsch-app"
    
    --> Creating resources ...
        deploymentconfig "jws-wsch-app" created
        service "jws-wsch-app" created
    --> Success
        Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
         'oc expose svc/jws-wsch-app'
        Run 'oc status' to view your app.
  9. Expose the service to make the application accessible to users:

    For example, to make the example jws-wsch-app application accessible, perform the following steps:

    1. Check the name of the service to expose:

      Copy to Clipboard Toggle word wrap
      $ oc get svc -o name

      The preceding command produces the following type of output:

      Copy to Clipboard Toggle word wrap
      service/jws-wsch-app
    2. Expose the service:

      Copy to Clipboard Toggle word wrap
      $ oc expose svc/jws-wsch-app

      The preceding command produces the following type of output:

      Copy to Clipboard Toggle word wrap
      route "jws-wsch-app" exposed
  10. Retrieve the address of the exposed route:

    Copy to Clipboard Toggle word wrap
    oc get routes --no-headers -o custom-columns='host:spec.host' jws-wsch-app
  11. Open a web browser and enter the URL to access the application.

    For example, to access the example jws-wsch-app application, enter the following URL:

    http://<address_of_exposed_route>/websocket-chat

    Note

    In the preceding example, replace <address_of_exposed_route> with the appropriate value for your deployment.

Additional resources

2.6. Creating a JWS for OpenShift application from source code

You can create a JWS for OpenShift application from source code.

For detailed information about creating new OpenShift applications from source code, see OpenShift.com - Creating an application from source code.

Prerequisites

Procedure

  1. Log in to the OpenShift instance:

    Copy to Clipboard Toggle word wrap
    $ oc login <url>
  2. Create a new project if required:

    Copy to Clipboard Toggle word wrap
    $ oc new-project <project-name>
    Note

    In the preceding example, replace <project-name> with the name of the project you want to create.

  3. Identify the JWS for OpenShift image stream to use for your application:

    Copy to Clipboard Toggle word wrap
    $ oc get is -n openshift | grep ^jboss-webserver | cut -f1 -d ' '

    The preceding command produces the following type of output:

    Copy to Clipboard Toggle word wrap
    jboss-webserver61-openjdk17-tomcat10-openshift-ubi8
    Note

    The -n openshift option specifies the project to use. The oc get is -n openshift command gets the image stream resources from the openshift project.

  4. Create the new OpenShift application from source code by using Red Hat JBoss Web Server for OpenShift images:

    Copy to Clipboard Toggle word wrap
    $ oc new-app \
     <source_code_location> \
     --image-stream=jboss-webserver61-openjdk17-tomcat10-openshift-ubi8:latest \
     --name=<openshift_application_name>

    For example:

    Copy to Clipboard Toggle word wrap
    $ oc new-app \
     https://github.com/web-servers/tomcat-websocket-chat-quickstart.git#main \
     --image-stream=jboss-webserver61-openjdk17-tomcat10-openshift-ubi8:latest \
     --context-dir='tomcat-websocket-chat' \
     --name=jws-wsch-app

    The preceding command adds the source code to the image and compiles the source code. The preceding command also creates the build configuration and services.

  5. To expose the application, perform the following steps:

    1. To check the name of the service to expose:

      Copy to Clipboard Toggle word wrap
      $ oc get svc -o name

      The preceding command produces the following type of output:

      Copy to Clipboard Toggle word wrap
      service/<openshift_application_name>
    2. To expose the service:

      Copy to Clipboard Toggle word wrap
      $ oc expose svc/<openshift_application_name>

      The preceding command produces the following type of output:

      Copy to Clipboard Toggle word wrap
      route "<openshift_application_name>" exposed
  6. To retrieve the address of the exposed route:

    Copy to Clipboard Toggle word wrap
    oc get routes --no-headers -o custom-columns='host:spec.host' <openshift_application_name>
  7. Open a web browser and enter the following URL to access the application:

    http://<address_of_exposed_route>/<java_application_name>

    Note

    In the preceding example, replace <address_of_exposed_route> and <java_application_name> with appropriate values for your deployment.

2.7. Adding additional JAR files in the tomcat/lib directory

You can use Docker to add additional Java Archive (JAR) files in the tomcat/lib directory.

Procedure

  1. Start the image in Docker:

    Copy to Clipboard Toggle word wrap
    docker run --network host -i -t -p 8080:8080 ImageURL
  2. Find the CONTAINER ID:

    Copy to Clipboard Toggle word wrap
     docker ps | grep <ImageName>
  3. Copy the library to the tomcat/lib/ directory:

    Copy to Clipboard Toggle word wrap
    docker cp <yourLibrary> <CONTAINER ID>:/opt/jws-6.1/tomcat/lib/
  4. Commit the changes to a new image:

    Copy to Clipboard Toggle word wrap
    docker commit <CONTAINER ID> <NEW IMAGE NAME>
  5. Create a new image tag:

    Copy to Clipboard Toggle word wrap
    docker tag <NEW IMAGE NAME>:latest <NEW IMAGE REGISTRY URL>:<TAG>
  6. Push the image to a registry:

    Copy to Clipboard Toggle word wrap
    docker push <NEW IMAGE REGISTRY URL>
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat, Inc.