Enterprise Java

Getting Started with Payara

Payara is an open-source application server designed for running modern enterprise Java applications. It is based on GlassFish but extends it with long-term support, performance improvements, security fixes, and production-ready features. Let us delve into an introduction to Java Jakarta EE using Payara.

1. Introduction to Payara Server

Payara Server is a full-featured, enterprise-grade Jakarta EE application server provided by Payara Services. It is built on top of GlassFish and extends it with long-term support, performance enhancements, security fixes, and production-ready tooling. Payara Server fully implements the Jakarta EE specification and supports a wide range of technologies, including Servlets, JSP, JSF, JPA, EJB, CDI, JAX-RS (RESTful services), JMS, and WebSockets. This makes it suitable for both traditional monolithic enterprise applications and modern, cloud-native architectures. In addition to standard Jakarta EE capabilities, Payara Server includes enterprise features such as monitoring, health checks, request tracing, advanced security integrations, and seamless support for containerized and orchestrated environments.

1.1 When to Use Payara Server

Payara Server is designed for applications that require a robust, standards-compliant runtime with enterprise-level reliability. You should consider using Payara Server when:

  • You need full Jakarta EE compatibility rather than a lightweight or partial implementation.
  • Your application relies heavily on enterprise technologies such as EJBs, JPA, JMS, or container-managed transactions.
  • You want a stable, production-ready alternative to GlassFish with ongoing maintenance and support.
  • You require built-in monitoring, health checks, and diagnostics without adding external tooling.
  • You plan to deploy enterprise applications using containers or orchestrators.

Payara Server is especially well-suited for large-scale systems, regulated environments, and teams that value long-term stability and adherence to open standards.

1.2 Installing Payara Server on Docker

Payara provides official Docker images that simplify running the server in containerized environments. These images are preconfigured with sensible defaults and can be easily customized for development, testing, and production. The following example demonstrates how to pull and run the latest Payara Server Full image using Docker:

# Pull the latest Payara Server Full image
docker pull payara/server-full

# Run Payara Server in detached mode
docker run -d \
  -p 8080:8080 \
  -p 4848:4848 \
  --name payara-server \
  payara/server-full

In this setup, port 8080 is used to access deployed applications, port 4848 exposes the Payara Admin Console for server configuration and management, and the container runs in detached mode, allowing Payara Server to operate in the background without blocking the terminal session.

For production deployments, it is recommended to externalize configuration, use persistent volumes for domain data, and integrate the container with orchestration platforms for scaling and high availability.

2. Hello World Application

2.1 Project Structure

A simple Jakarta EE “Hello World” application can be created using a RESTful service. Below is a minimal example using JAX-RS.

hello-world/
 ├── src/main/java
 │   └── com/example/hello
 │       ├── ApplicationConfig.java
 │       └── HelloResource.java
 └── src/main/webapp
     └── WEB-INF
         └── web.xml

2.2 Java Code Example

2.2.1 ApplicationConfig.java

package com.example.hello;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

@ApplicationPath("/api")
public class ApplicationConfig extends Application {
  // No additional configuration required
}

This code defines a Jakarta REST configuration class that extends the Application class and uses the @ApplicationPath annotation to specify “/api” as the base URL for all REST endpoints in the application, meaning that any JAX-RS resources deployed in this project will be accessible under the /api path without requiring additional configuration.

2.2.2 HelloResource.java

package com.example.hello;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/hello")
public class HelloResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return "Hello World from Payara Server!";
    }
}

This code defines a simple Jakarta REST resource class mapped to the /hello path, where the @GET annotation specifies that the method handles HTTP GET requests, the @Produces annotation indicates that the response is returned as plain text, and the hello() method sends a simple “Hello World from Payara Server!” message when the endpoint is accessed.

2.2.3 web.xml (Deployment Descriptor)

Although modern Jakarta EE applications can rely heavily on annotations, the web.xml file—also known as the deployment descriptor—still plays an important role in defining application-level configuration. In Payara Server, web.xml is optional for simple applications, but it is commonly included for clarity, compatibility, and advanced configuration needs.

For this Hello World application, the web.xml file is minimal and primarily serves to declare the Jakarta EE version and define the application as a web module.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
                             https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
         version="6.0">

    <display-name>Hello World Application</display-name>

</web-app>

In this configuration:

  • The version attribute specifies the Jakarta Servlet specification version used by the application.
  • The XML namespace and schema location ensure compatibility with Jakarta EE–compliant application servers such as Payara Server.
  • No servlet or REST mappings are required because JAX-RS configuration is handled through annotations (via @ApplicationPath and @Path).

It is important to note that if web.xml and annotations define overlapping configuration (for example, servlet mappings), the settings in web.xml take precedence. In more complex applications, this file is often used for configuring filters, listeners, security constraints, welcome pages, and session settings. For simple REST-based applications like this example, web.xml can remain minimal—or even be omitted entirely—but including it helps document the application structure and makes future extensions easier.

2.3 Deploying the Application

Once development is complete, package the application as a WAR (Web Application Archive) file using your build tool such as Maven or Gradle. This WAR file contains all compiled classes, configuration files, and dependencies required to run the application on the server.

You can deploy the application to Payara Server in multiple ways. The simplest approach is to copy the WAR file into Payara’s deployments directory, where the server automatically detects and deploys it at runtime. This method is commonly used for local development and quick testing.

Alternatively, you can deploy the application using the Payara Admin Console, which provides a web-based interface for managing applications. By accessing the Admin Console, you can upload the WAR file, configure deployment settings, manage application versions, and monitor the deployment status.

After deployment, the application becomes accessible via the configured server ports and context path, allowing clients to invoke the exposed REST endpoints through a web browser or API client.

2.3.1 Output

After the application has been successfully deployed, you can access the REST endpoint using a web browser or an API client by navigating to the following URL:

http://localhost:8080/hello-world/api/hello

When the endpoint is invoked, the server processes the request and returns the following plain text response:

Hello World from Payara Server!

This output confirms that the application is running correctly, the REST resource is accessible, and Payara Server is successfully handling HTTP requests.

3. Conclusion

Payara is a powerful and reliable application server for building enterprise-grade Java applications. With full Jakarta EE support, Docker compatibility, and a strong focus on production readiness, Payara Server is an excellent choice for both traditional and modern cloud-native deployments. By using Payara, developers can focus on business logic while relying on a stable, standards-compliant platform to handle scalability, security, and performance.

Yatin Batra

An experience full-stack engineer well versed with Core Java, Spring/Springboot, MVC, Security, AOP, Frontend (Angular & React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button