Este conteúdo não está disponível no idioma selecionado.

Chapter 2. Build and Run a Java Application on the JBoss EAP for OpenShift Image


The following workflow demonstrates using the Source-to-Image (S2I) process to build and run a Java application on the JBoss EAP for OpenShift image.

As an example, the kitchensink quickstart is used in this procedure. It demonstrates a Java EE 7 web-enabled database application using JSF, CDI, EJB, JPA, and Bean Validation. See the kitchensink quickstart that ships with JBoss EAP 7 for more information.

2.1. Prerequisites

This workflow assumes that you already have an active OpenShift Online subscription and that you have installed the OpenShift CLI.

2.2. Prepare OpenShift for Application Deployment

  1. Log in to your OpenShift instance using the oc login command.
  2. Create a new project in OpenShift.

    A project allows a group of users to organize and manage content separately from other groups. You can create a project in OpenShift using the following command.

    $ oc new-project PROJECT_NAME
    Copy to Clipboard Toggle word wrap

    For example, for the kitchensink quickstart, create a new project named eap-demo using the following command.

    $ oc new-project eap-demo
    Copy to Clipboard Toggle word wrap
  3. Create a keystore.

    JBoss EAP for OpenShift requires a keystore to be imported to properly install and configure the image on your OpenShift instance.

    Warning

    The following commands generate a self-signed certificate, but for production environments Red Hat recommends that you use your own SSL certificate purchased from a verified Certificate Authority (CA) for SSL-encrypted connections (HTTPS).

    You can use the Java keytool command to generate a keystore using the following command.

    $ keytool -genkey -keyalg RSA -alias ALIAS_NAME -keystore KEYSTORE_FILENAME.jks -validity 360 -keysize 2048
    Copy to Clipboard Toggle word wrap

    For example, for the kitchensink quickstart, use the following command to generate a keystore.

    $ keytool -genkey -keyalg RSA -alias eapdemo-selfsigned -keystore keystore.jks -validity 360 -keysize 2048
    Copy to Clipboard Toggle word wrap
  4. Create a secret from the keystore.

    Create a secret from the previously created keystore using the following command.

    $ oc secrets new SECRET_NAME KEYSTORE_FILENAME.jks
    Copy to Clipboard Toggle word wrap

    For example, for the kitchensink quickstart, use the following command to create a secret.

    $ oc secrets new eap7-app-secret keystore.jks
    Copy to Clipboard Toggle word wrap

2.3. Import the Latest JBoss EAP for OpenShift Image Streams and Templates

Use the following command to import the latest JBoss EAP for OpenShift image streams and templates into your OpenShift project’s namespace.

for resource in \
  eap71-image-stream.json \
  eap71-amq-persistent-s2i.json \
  eap71-amq-s2i.json \
  eap71-basic-s2i.json \
  eap71-https-s2i.json \
  eap71-mongodb-persistent-s2i.json \
  eap71-mongodb-s2i.json \
  eap71-mysql-persistent-s2i.json \
  eap71-mysql-s2i.json \
  eap71-postgresql-persistent-s2i.json \
  eap71-postgresql-s2i.json \
  eap71-sso-s2i.json
do
  oc replace --force -f \
https://raw.githubusercontent.com/jboss-openshift/application-templates/master/eap/${resource}
done
Copy to Clipboard Toggle word wrap
Note

The JBoss EAP image streams and templates imported using the above command are only available within that OpenShift project.

If you have administrative access to the general openshift namespace and want the image streams and templates to be accessible by all projects, add -n openshift to the oc replace line of the command. For example:

...
oc replace -n openshift --force -f \
...
Copy to Clipboard Toggle word wrap

2.4. Deploy a JBoss EAP Source-to-Image (S2I) Application to OpenShift

  1. Create a new OpenShift application using the JBoss EAP for OpenShift image and your Java application’s source code. Red Hat recommends using one of the provided JBoss EAP for OpenShift templates for S2I builds.

    For example, for the kitchensink quickstart, use the following command to use the eap71-basic-s2i template with the kitchensink source code on GitHub.

    oc new-app --template=eap71-basic-s2i \
    1
    
     -p IMAGE_STREAM_NAMESPACE="eap-demo" \
    2
    
     -p SOURCE_REPOSITORY_URL="https://github.com/jboss-developer/jboss-eap-quickstarts" \
    3
    
     -p SOURCE_REPOSITORY_REF="7.1.0.GA" \
    4
    
     -p CONTEXT_DIR="kitchensink"
    5
    Copy to Clipboard Toggle word wrap
    1
    The template to use.
    2
    The latest images streams and templates were imported into the project’s namespace, so you must specify the namespace of where to find the image stream. This is usually the OpenShift project’s name.
    3
    URL to the repository containing the application source code.
    4
    The Git repository reference to use for the source code. This can be a Git branch or tag reference.
    5
    The directory within the source repository to build.
    Note

    A template can specify default values for many template parameters, and you might have to override some, or all, of the defaults. To see template information, including a list of parameters and any default values, use the command oc describe template TEMPLATE_NAME.

  2. Retrieve the name of the build configuration.

    $ oc get bc -o name
    Copy to Clipboard Toggle word wrap
  3. Use the name of the build configuration from the previous step to view the Maven progress of the build.

    $ oc logs -f buildconfig/BUILD_CONFIG_NAME
    Copy to Clipboard Toggle word wrap

    For example, for the kitchensink quickstart, the following command shows the progress of the Maven build.

    $ oc logs -f buildconfig/eap-app
    Copy to Clipboard Toggle word wrap

2.5. Post Deployment Tasks

Depending on your application, some tasks might need to be performed after your OpenShift application has been built and deployed. This might include exposing a service so that the application is viewable from outside of OpenShift, or scaling your application to a specific number of replicas.

  1. Get the service name of your application using the following command.

    $ oc get service
    Copy to Clipboard Toggle word wrap
  2. Expose the main service as a route so you can access your application from outside of OpenShift. For example, for the kitchensink quickstart, use the following command to expose the required service and port.

    $ oc expose service/eap-app --port=8080
    Copy to Clipboard Toggle word wrap
    Note

    If you used a template to create the application, the route might already exist. If it does, continue on to the next step.

  3. Get the URL of the route.

    $ oc get route
    Copy to Clipboard Toggle word wrap
  4. Access the application in your web browser using the URL. The URL is the value of the HOST/PORT field from previous command’s output.

    If your application does not use the JBoss EAP root context, append the context of the application to the URL. For example, for the kitchensink quickstart, the URL might be http://HOST_PORT_VALUE/kitchensink/.

  5. Optionally, you can also scale up the application instance by running the following command. This increases the number of replicas to 3.

    $ oc scale deploymentconfig DEPLOYMENTCONFIG_NAME --replicas=3
    Copy to Clipboard Toggle word wrap

    For example, for the kitchensink quickstart, use the following command to scale up the application.

    $ oc scale deploymentconfig eap-app --replicas=3
    Copy to Clipboard Toggle word wrap
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2026 Red Hat
Voltar ao topo