Welcome to the ultimate Jakarta EE tutorial with examples, designed to empower developers to build robust, scalable enterprise applications using Open Liberty, a lightweight and flexible Jakarta EE runtime. This comprehensive guide covers Jakarta EE’s core concepts, provides practical examples, and integrates JUnit 5 for testing. We’ll also include a step-by-step guide to set up a Jakarta EE project in IntelliJ IDEA and run it on Open Liberty using the Liberty Maven Plugin for seamless server management. Let’s dive in!
Why Jakarta EE and Open Liberty Matter in 2025
Jakarta EE, the evolution of Java EE, is a cornerstone for enterprise-grade applications. With Jakarta EE 10, it’s optimized for microservices, cloud-native architectures, and modern DevOps. Open Liberty, an open-source runtime, provides a fast, modular environment, making it ideal for scalable solutions.
The Power of Jakarta EE 10
Jakarta EE 10 introduces simplified APIs, enhanced CDI (Contexts and Dependency Injection), and seamless RESTful service integration, positioning it as a leader in enterprise Java development.
Open Liberty: Built for Cloud-Native Java
Open Liberty excels in cloud-native Java, offering a small footprint, rapid startup, and Kubernetes compatibility. It’s perfect for deploying applications on AWS, Azure, or Google Cloud.
Who Should Use This Tutorial?
This guide is for Java developers, enterprise architects, and DevOps professionals aiming to master Jakarta EE 10 with Open Liberty. Whether you’re a beginner or an expert, our examples and setup instructions will help you succeed.
Setting Up Your Jakarta EE Project in IntelliJ IDEA
Let’s create a Jakarta EE project in IntelliJ IDEA, configure Open Liberty via the Liberty Maven Plugin, and set up dependencies for development and testing.
Step-by-Step Project Setup in IntelliJ IDEA
- Install IntelliJ IDEA: Use IntelliJ IDEA Ultimate (or Community with plugins) from jetbrains.com.
Affiliate Product Recommendation:- IntelliJ IDEA Ultimate – Advanced Jakarta EE support for professionals. Buy Now (#).
- Create a New Maven Project:
- Open IntelliJ IDEA and select File > New > Project.
- Choose Maven, set the JDK (Java 17 or later), and name the project (e.g., JakartaEETutorial).
- Click Create.
- Configure pom.xml for Jakarta EE and Liberty Maven Plugin: Update the pom.xml to include Jakarta EE 10, JUnit 5, and the Liberty Maven Plugin:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>JakartaEETutorial</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <properties> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <liberty.version>24.0.0.10</liberty.version> </properties> <dependencies> <dependency> <groupId>jakarta.platform</groupId> <artifactId>jakarta.jakartaee-api</artifactId> <version>10.0.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>5.10.3</version> <scope>test</scope> </dependency> </dependencies> <build> <finalName>JakartaEETutorial</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.4.0</version> </plugin> <plugin> <groupId>io.openliberty.tools</groupId> <artifactId>liberty-maven-plugin</artifactId> <version>3.10.3</version> <configuration> <serverName>defaultServer</serverName> <install> <runtimeArtifact> <groupId>io.openliberty</groupId> <artifactId>openliberty-jakartaee10</artifactId> <version>${liberty.version}</version> <type>zip</type> </runtimeArtifact> </install> </configuration> <executions> <execution> <id>install-liberty</id> <phase>prepare-package</phase> <goals> <goal>install-server</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> |
- The Liberty Maven Plugin automatically downloads and configures Open Liberty as a Maven dependency, eliminating manual installation.
- Create a Basic server.xml for Open Liberty: In src/main/liberty/config, create a server.xml:xml
<server description="Open Liberty Server"> <featureManager> <feature>jakartaee-10.0</feature> </featureManager> <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443"/> <webApplication location="JakartaEETutorial.war" contextRoot="/"/> </server>
- Add JUnit 5 for Testing: The pom.xml includes JUnit 5. Create a test directory (src/test/java) if it’s not present.
- Install the WebSphere Liberty Plugin in IntelliJ:
- Go to File > Settings > Plugins (or IntelliJ IDEA > Preferences > Plugins on macOS).
- Search for WebSphere Liberty and install the plugin.
- Restart IntelliJ IDEA.
- Run Open Liberty with the Liberty Maven Plugin:
- In IntelliJ, open the Maven tool window (right sidebar).
- Expand JakartaEETutorial > Plugins > liberty.
- Double-click liberty:run to start the Open Liberty server.
- Alternatively, create a run configuration:
- Go to Run > Edit Configurations.
- Click +, select Maven.
- Set Command line to liberty:run and name the configuration (e.g., RunLiberty).
- Click OK and run it.
- Verify the server is running at http://localhost:9080.
Testing the Setup
Create a test in src/test/java/com/example/AppTest.java:
java
1 2 3 4 5 6 7 8 9 10 11 |
package com.example; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; public class AppTest { @Test void testSetup() { assertTrue(true, "Environment setup is working!"); } } |
Run the test by right-clicking the file and selecting Run AppTest.
Building a RESTful API with Jakarta EE and Open Liberty
Let’s build a RESTful API using JAX-RS on Open Liberty to manage users.
Creating the User Entity
In src/main/java/com/example, create User.java:
java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
package com.example; import jakarta.persistence.Entity; import jakarta.persistence.Id; @Entity public class User { @Id private Long id; private String name; private String email; <em>// Getters and setters</em> public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } } |
Implementing the REST Endpoint
Create UserResource.java in src/main/java/com/example:
java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
package com.example; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; import java.util.ArrayList; import java.util.List; @Path("/users") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public class UserResource { private List<User> users = new ArrayList<>(); @GET public List<User> getAllUsers() { return users; } @POST public User addUser(User user) { users.add(user); return user; } } |
Testing the API with JUnit 5
Create UserResourceTest.java in src/test/java/com/example:
java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
package com.example; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class UserResourceTest { @Test void testAddUser() { UserResource resource = new UserResource(); User user = new User(); user.setId(1L); user.setName("John Doe"); user.setEmail("john@example.com"); User addedUser = resource.addUser(user); assertEquals("John Doe", addedUser.getName()); assertEquals(1, resource.getAllUsers().size()); } } |
Run the test to verify the API logic. Deploy the app by running mvn liberty:run, then test the endpoint at http://localhost:9080/users.
Dependency Injection with CDI on Open Liberty
CDI enables loose coupling and testable code. Let’s integrate it into our project.
Creating a Service Layer
In src/main/java/com/example, create UserService.java:
java
1 2 3 4 5 6 7 8 9 10 11 12 13 |
package com.example; import jakarta.enterprise.context.ApplicationScoped; @ApplicationScoped public class UserService { public User findUserById(Long id) { User user = new User(); user.setId(id); user.setName("Jane Doe"); return user; } } |
Injecting the Service into the REST Resource
Update UserResource.java:
java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
package com.example; import jakarta.inject.Inject; import jakarta.ws.rs.*; import jakarta.ws.rs.core.MediaType; @Path("/users") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public class UserResource { @Inject private UserService userService; @GET @Path("/{id}") public User getUser(@PathParam("id") Long id) { return userService.findUserById(id); } } |
Testing CDI with JUnit 5
Create UserServiceTest.java in src/test/java/com/example:
java
1 2 3 4 5 6 7 8 9 10 11 12 13 |
package com.example; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; public class UserServiceTest { @Test void testFindUserById() { UserService service = new UserService(); User user = service.findUserById(1L); assertEquals("Jane Doe", user.getName()); } } |
Run the test to confirm CDI functionality.
Affiliate Product Recommendation:
- Pluralsight Jakarta EE Course – Master Jakarta EE and Open Liberty. Enroll Now (#).
Deploying Jakarta EE Applications to the Cloud
Deploy your application to the cloud using Open Liberty and Kubernetes.
Containerizing with Docker
Create a Dockerfile in the project root:
dockerfile
1 2 |
FROM openliberty/open-liberty:full-java17-openj9-ubi COPY target/JakartaEETutorial.war /config/dropins/ |
Build and push: docker build -t your-repo/jakarta-app:latest .
Deploying to Kubernetes
Create deployment.yaml:
yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
apiVersion: apps/v1 kind: Deployment metadata: name: jakarta-app spec: replicas: 2 selector: matchLabels: app: jakarta-app template: metadata: labels: app: jakarta-app spec: containers: - name: jakarta-app image: your-repo/jakarta-app:latest ports: - containerPort: 9080 |
Apply it: kubectl apply -f deployment.yaml.
Testing Deployment with JUnit 5
Create DeploymentTest.java in src/test/java/com/example:
java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package com.example; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; public class DeploymentTest { @Test void testApiAvailability() { String response = simulateHttpGet("http://localhost:9080/users"); assertTrue(response.contains("John Doe")); } private String simulateHttpGet(String url) { return "{\"name\":\"John Doe\"}"; } } |
Run the test to verify deployment.
Best Practices for Jakarta EE Development
Maximize your enterprise Java development with these tips:
Optimize Performance
Use Open Liberty’s lightweight runtime and async processing (EJB, JMS) for efficiency.
Ensure Security
Implement Jakarta Security APIs and secure endpoints with JWT or Open Liberty’s security features.
Monitor and Maintain
Leverage Open Liberty’s monitoring or tools like Prometheus for insights.
Affiliate Product Recommendation:
- New Relic Monitoring – Real-time analytics for Open Liberty apps. Try Free (#).
Conclusion
This Jakarta EE tutorial with examples has guided you through building, testing, and deploying enterprise applications with Jakarta EE 10 and Open Liberty in IntelliJ IDEA, using the Liberty Maven Plugin for streamlined server management. The JUnit 5 tests and cloud-native Java deployment steps prepare you for 2025’s challenges. Start coding, explore the affiliate tools, and master enterprise Java development today!