Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

How to use Eclipse JKube Maven plugins in 3 steps

July 27, 2020
Marc Nuri
Related topics:
Developer toolsJavaKubernetes
Related products:
Red Hat OpenShift

    Before we had Spring Boot and similar frameworks, a web app container was the main requirement for deploying Java web applications. We now live in the age of microservices, and many Java applications are developed on top of Quarkus, Thorntail, or Spring Boot. But some use cases still require an old-school web application.

    In this article, you will learn how to deploy a Java web application (WAR) into a Kubernetes or Red Hat OpenShift cluster using Eclipse JKube. I'll show you how easy it is to make a monolithic Java web application cloud-native, just by adding Eclipse JKube Maven plugins.

    The example web application

    For the purpose of this article, we'll work with a very simple Spring Web MVC application. The following sample shows the most relevant parts of the Maven project's pom.xml:

    <!-- ... -->
    <packaging>war</packaging>
    <!-- ... -->
    <properties>
      <maven.compiler.source>11</maven.compiler.source>
      <maven.compiler.target>11</maven.compiler.target>
      <failOnMissingWebXml>false</failOnMissingWebXml>
      <!-- ... -->
      <jkube.enricher.jkube-service.type>NodePort</jkube.enricher.jkube-service.type>
    </properties>
    <dependencies>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${version.spring}</version>
      </dependency>
      <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.1</version>
        <scope>provided</scope>
      </dependency>
    </dependencies>
    <build>
      <plugins>
        <plugin>
          <groupId>org.eclipse.jkube</groupId>
          <artifactId>kubernetes-maven-plugin</artifactId>
          <version>${version.jkube}</version>
        </plugin>
        <!-- ... -->
      </plugins>
    </build>
    

    First, notice the packaging element, which indicates that the resulting artifact should be packaged as a war file, which is the usual format for Java web applications.

    In the properties section, notice that the project is configured for Java 11. We'll need a compatible JDK to build the project. We use the failOnMissingWebXml option to configure the maven-war-plugin so that it won't fail due to a missing web.xml file. (You will see soon what we're using instead.) Finally, there's a JKube-specific property, jkube.enricher.jkube-service.type. This property configures JKube to create a service-resource manifest using NodePort as the spec.type.

    In the dependencies section, we find just two dependencies. The spring-webmvc dependency lets us use the Spring Web MVC framework. The javax.servlet-api dependency provides compile-time support for the Java Servlet API, which is provided by the web application container at runtime.

    Finally, in the plugins section, we've configured the Eclipse JKube dependency. Note that we can use either the kubernetes-maven-plugin or the openshift-maven-plugin. The choice of plugin depends on the cluster we want to target, but we only need one of them.

    The configuration is simple and straightforward. The only thing different from a typical, old-school Java web application is the Eclipse JKube plugin dependency.

    Java classes in the example project

    The example project contains three Java classes: ExampleInitializer, ExampleConfiguration, and ExampleResource. First, ExampleInitializer is a WebApplicationInitializer implementation. We're using it instead of the standard WEB-INF/web.xml deployment descriptor to configure the ServletContext programmatically.

    The following code shows how ExampleInitializer lets us register Spring's DispatcherServlet without any additional XML configuration:

    final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(ExampleConfiguration.class);
    context.setServletContext(servletContext);
    final ServletRegistration.Dynamic dsr = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
    dsr.setLoadOnStartup(1);
    dsr.addMapping("/");
    

    The ExampleConfiguration class is a Spring-specific configuration enabling Spring MVC.

    Finally, ExampleResource is a standard Spring @RestController. It has a single request mapping that responds Hello!!! to any GET request.

    Deploy the web application into Kubernetes

    We'll start by deploying the example web application into Kubernetes; then, I'll show you how to make a couple of adjustments and deploy it into OpenShift.

    Step 1: Build the application

    The first step is to build the project just as we would build any other Maven web application project. Running mvn clean package generates a new war artifact in the target directory of target/example-0.0.0-SNAPSHOT.war.

    For the purpose of this example, we'll use Minikube. So that we can pull the image from the cluster without having to push it to a shared registry, we'll use Minikube's docker daemon, eval $(minikube docker-env).

    We can now issue the mvn k8s:build command to build the docker image for our application, as shown in Figure 1.

    mvn k8s:build
    Figure 1: Build the docker image for the application.

    A new docker image will be tagged as webapp/example:latest in our docker registry.

    Step 2: Create the cluster configuration

    Next, we create the required cluster configuration resource manifests and apply them to the kubectl- configured cluster, as shown in Figure 2.

    mvn k8s:resource k8s:apply
    Figure 2: Create and deploy the cluster configuration.

    The previous commands will generate the Kubernetes configuration manifests in target/classes/META-INF/jkube/kubernetes.yml, and will apply them to the cluster.

    Step 3: Verify that the application is running

    Finally, we verify that everything is running by entering the commands shown in Figure 3.

    kubectl get pod
    Figure 3: Verify that the application is running.

    Deploy the web application into OpenShift

    Following similar steps to those in the previous section, we can seamlessly deploy the example web application to an OpenShift cluster, just by using the openshift-maven-plugin instead of the kubernetes-maven-plugin:

    <build>
      <plugins>
        <plugin>
          <groupId>org.eclipse.jkube</groupId>
          <artifactId>openshift-maven-plugin</artifactId>
          <version>${version.jkube}</version>
        </plugin>
      </plugins>
    </build>
    

    In this case, the plugin prefix is oc instead of k8s, but the goals to be run are the same. Note that in this case, the build step uses S2I instead of docker to perform the build.

    mvn oc:build
    Figure 4: Build the container image using S2I binary build strategy for the application.
    mvn k8s:resource k8s:apply
    Figure 5: Create and deploy the cluster OpenShift specific configuration.

    The developer experience

    You've seen how Eclipse JKube lets us easily deploy a web application to the cloud. It also has other features to ease our lives as developers. Let's look at how Eclipse JKube enhances a typical log retrieval.

    Log retrieval

    If we want to print the logs for the web application that we just deployed, we can simply run mvn k8s:log. The logs will be printed and followed (or tailed) in the current console, as shown in Figure 6.

    mvn k8s:log
    Figure 6: Logs for the Kubernetes application deployment.

    The screenshot in Figure 6 shows the log for the application we've just deployed on Kubernetes. You can see that the Apache Tomcat web application container was started and that the web application was deployed into the ROOT context.

    Note: By default, Eclipse JKube uses Apache Tomcat as its web application container, via the jkube/jkube-tomcat9-binary-s2i base image. In a follow-up article, I will show you how to use different web application containers (such as Jetty), just by adding container-specific files.

    Conclusion

    In this article, you've seen how easy it is to convert an old-school Java web application into a full-fledged cloud-native application, just by adding the Eclipse JKube plugin dependency to your Maven POM. The complete source code for the examples is available on GitHub.

    If you're interested in learning more about Eclipse JKube, you can visit our main GitHub repository, website, or Gitter channel. And don't forget to follow us on Twitter!

    Last updated: September 19, 2023

    Related Posts

    • Introduction to Eclipse JKube: Java tooling for Kubernetes and Red Hat OpenShift

    • Java development on top of Kubernetes using Eclipse JKube

    • Modernizing Enterprise Java: A cloud native guide for developers

    Recent Posts

    • Streamlining Red Hat OpenShift support with the new support log gather operator

    • A day in the life of an NVIDIA H100 on Red Hat OpenShift 5

    • Migrate BuildConfigs to builds for Red Hat OpenShift with one plug-in install

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    What’s up next?

    This ebook will show you how to modernize traditional, monolithic Java-based applications into cloud-native models with Kubernetes.

    Get the e-book
    Red Hat Developers logo

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    Red Hat Developer

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility
    Ask AI