Powerful technologies are essential in the world of enterprise applications. Discover how Jakarta EE libraries are revolutionizing development in the final part of our series.
Remote control made easy: Jakarta RPC in focus
Jakarta RPC offers support for remote procedure calls. This allows you to execute functions or methods on a remote server. This technology facilitates communication between distributed systems.
<dependency> <groupId>jakarta.rpc</groupId> <artifactId>jakarta.rpc-api</artifactId> </dependency>
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface MessageService extends Remote {
String sendMessage(String message) throws RemoteException;
}
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
public class MessageServiceImpl extends UnicastRemoteObject implements MessageService {
protected MessageServiceImpl() throws RemoteException {
super();
}
public String sendMessage(String message) throws RemoteException {
return "Server received: " + message;
}
public static void main(String[] args) {
try {
MessageServiceImpl service = new MessageServiceImpl();
Registry registry = LocateRegistry.createRegistry(1099);
registry.bind("MessageService", service);
System.out.println("MessageService bound in registry");
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class MessageClient {
public static void main(String[] args) {
try {
Registry registry = LocateRegistry.getRegistry("localhost", 1099);
MessageService service = (MessageService) registry.lookup("MessageService");
String response = service.sendMessage("Hello Server!");
System.out.println("Response: " + response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Security solutions for companies: Jakarta Security
Jakarta Security provides a comprehensive security framework for Jakarta EE applications that includes authentication, authorization and identity management. It ensures the protection and security of applications.
<dependency> <groupId>jakarta.security</groupId> <artifactId>jakarta.security-api</artifactId> </dependency>
import jakarta.security.enterprise.authentication.mechanism.http.BasicAuthenticationMechanismDefinition;
import jakarta.security.enterprise.identitystore.annotation.EmbeddedIdentityStoreDefinition;
@BasicAuthenticationMechanismDefinition(realmName = "example realms")
@EmbeddedIdentityStoreDefinition({
@EmbeddedIdentityStoreDefinition.User(name = "user", password = "password", roles = "USER"),
@EmbeddedIdentityStoreDefinition.User(name = "admin", password = "admin", roles = "ADMIN")
})
public class SecurityConfig {
// Sicherheitskonfiguration in einer Anwendungsklasse
}
import jakarta.annotation.security.RolesAllowed;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
@Path("secure")
public class SecureResource {
@GET
@RolesAllowed("ADMIN")
@Produces(MediaType.TEXT_PLAIN)
public String adminAccess() {
return "This is secured information accessible to ADMIN role.";
}
}
Jakarta Servlet: The basis for web applications
Jakarta Servlet is a fundamental technology for the development of web applications that process HTTP requests and generate dynamic content. Servlets often form the basis for other web technologies.
<dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> </dependency>
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h1>Hello, Jakarta Servlet!</h1>");
out.println("</body></html>");
}
}
SOAP messages with attachments: Jakarta SOAP with Attachments
Jakarta SOAP with Attachments enables the creation and manipulation of SOAP messages with attachments that are used in web service applications for communication between services.
<dependency> <groupId>jakarta.xml.soap</groupId> <artifactId>jakarta.xml.soap-api</artifactId> </dependency>
import jakarta.jws.WebMethod;
import jakarta.jws.WebService;
import jakarta.jws.soap.SOAPBinding;
@WebService
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
public interface CalculatorService {
@WebMethod
int add(int a, int b);
@WebMethod
int subtract(int a, int b);
}
import jakarta.jws.WebService;
@WebService(endpointInterface = "com.example.CalculatorService")
public class CalculatorServiceImpl implements CalculatorService {
@Override
public int add(int a, int b) {
return a + b;
}
@Override
public int subtract(int a, int b) {
return a - b;
}
}
import jakarta.xml.ws.Endpoint;
public class CalculatorServicePublisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/ws/calculator", new CalculatorServiceImpl());
System.out.println("CalculatorService is published at http://localhost:8080/ws/calculator");
}
}
User-defined JSP tags: Jakarta Standard Tag Library (JSTL)
Jakarta Standard Tag Library (JSTL) provides a collection of custom JSP tags that simplify common tasks such as loops and conditional logic and promote the separation of presentation and logic layers.
<dependency> <groupId>jakarta.servlet.jsp.jstl</groupId> <artifactId>jakarta.servlet.jsp.jstl-api</artifactId> </dependency>
<%@ taglib uri="http://xmlns.jcp.org/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<title>Benutzerliste</title>
</head>
<body>
<h2>Benutzerliste:</h2>
<ul>
<c:forEach var="user" items="${userList}">
<li>${user}</li>
</c:forEach>
</ul>
</body>
</html>
User interfaces with components: Jakarta Server Faces (JSF)
Jakarta Server Faces (JSF) is a component-based framework for creating user interfaces in web applications that offers a variety of UI components and simple state management.
<dependency> <groupId>jakarta.faces</groupId> <artifactId>jakarta.faces-api</artifactId> </dependency>
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
import java.util.Arrays;
import java.util.List;
@Named
@RequestScoped
public class UserBean {
private List<String> users = Arrays.asList("Alice", "Bob", "Charlie");
public List<String> getUsers() {
return users;
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Benutzerliste</title>
</h:head>
<h:body>
<h2>Benutzerliste:</h2>
<ul>
<h:repeat value="#{userBean.users}" var="user">
<li>#{user}</li>
</h:repeat>
</ul>
</h:body>
</html>
Dynamic web content: Jakarta Server Pages (JSP)
Jakarta Server Pages (JSP) enables the creation of dynamic web content by embedding Java code in HTML. This supports the separation of presentation logic and business logic.
<dependency> <groupId>jakarta.servlet.jsp</groupId> <artifactId>jakarta.servlet.jsp-api</artifactId> </dependency>
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
@WebServlet("/userList")
public class UserServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<String> users = Arrays.asList("Alice", "Bob", "Charlie");
request.setAttribute("userList", users);
request.getRequestDispatcher("/userList.jsp").forward(request, response);
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://xmlns.jcp.org/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<title>Benutzerliste</title>
</head>
<body>
<h2>Benutzerliste:</h2>
<ul>
<c:forEach var="user" items="${userList}">
<li>${user}</li>
</c:forEach>
</ul>
</body>
</html>
Consistency in applications: Jakarta Transactions (JTA)
Jakarta Transactions (JTA) defines a transaction management system that enables transactions to be coordinated across multiple resources to ensure consistency in applications.
<dependency> <groupId>jakarta.transaction</groupId> <artifactId>jakarta.transaction-api</artifactId> </dependency>
import jakarta.annotation.Resource;
import jakarta.ejb.Stateless;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.transaction.UserTransaction;
@Stateless
public class ProductService {
@PersistenceContext
private EntityManager em;
@Resource
private UserTransaction userTransaction;
public void createProduct(String name, double price) {
try {
userTransaction.begin();
Product product = new Product();
product.setName(name);
product.setPrice(price);
em.persist(product);
userTransaction.commit();
} catch (Exception e) {
e.printStackTrace();
try {
userTransaction.rollback();
} catch (Exception rollbackException) {
rollbackException.printStackTrace();
}
}
}
}
Validate JavaBeans: Jakarta Validation (Bean Validation)
Jakarta Validation provides an API for validating JavaBeans. With the help of annotations, validation rules can be defined directly in bean classes.
<dependency> <groupId>jakarta.validation</groupId> <artifactId>jakarta.validation-api</artifactId> </dependency>
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.Max;
public class Product {
@NotNull
private Long id;
@NotNull
@Size(min = 2, max = 50)
private String name;
@Min(0)
private double price;
...
}
Metadata for web services: Jakarta WebServices Metadata
This specification defines metadata for web services that facilitate the description and configuration of web service endpoints and support annotation-based configuration.
<dependency> <groupId>jakarta.xml.ws</groupId> <artifactId>jakarta.xml.ws-api</artifactId> </dependency>
Bidirectional communication: Jakarta WebSocket
Jakarta WebSocket offers an API for implementing WebSocket communication. This enables bidirectional, event-driven communication between client and server.
<dependency> <groupId>jakarta.websocket</groupId> <artifactId>jakarta.websocket-api</artifactId> </dependency>
import jakarta.websocket.OnMessage;
import jakarta.websocket.server.ServerEndpoint;
import jakarta.websocket.Session;
import java.io.IOException;
@ServerEndpoint("/echo")
public class EchoEndpoint {
@OnMessage
public void onMessage(String message, Session session) throws IOException {
System.out.println("Received: " + message);
session.getBasicRemote().sendText("Echo: " + message);
}
}
Connecting XML and Java: Jakarta XML Binding (JAXB)
Jakarta XML Binding (JAXB) provides an API for converting Java objects into XML and vice versa.
<dependency> <groupId>jakarta.xml.bind</groupId> <artifactId>jakarta.xml.bind-api</artifactId> </dependency>
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.*;
import java.io.StringReader;
import java.io.StringWriter;
@XmlRootElement
class Person {
private String name;
private int age;
@XmlElement
public String getName() { return name; }
public void setName(String name) { this.name = name; }
@XmlElement
public int getAge() { return age; }
public void setAge(int age) { this.age = age; }
}
public class JaxbExample {
public static void main(String[] args) throws Exception {
Person p = new Person();
p.setName("Alice");
p.setAge(30);
// Marshalling (Objekt → XML)
JAXBContext context = JAXBContext.newInstance(Person.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter writer = new StringWriter();
marshaller.marshal(p, writer);
String xml = writer.toString();
System.out.println(xml);
// Unmarshalling (XML → Objekt)
Unmarshaller unmarshaller = context.createUnmarshaller();
Person copy = (Person) unmarshaller.unmarshal(new StringReader(xml));
System.out.println("Name: " + copy.getName() + ", Age: " + copy.getAge());
}
}
XML-based registries: Jakarta XML Registries
This specification provides access to XML-based registry services that provide information about available web services and other resources. This facilitates the discovery and use of services.
<dependency> <groupId>jakarta.xml.registry</groupId> <artifactId>jakarta.xml.registry-api</artifactId> </dependency>
import jakarta.xml.registry.*;
import java.util.Properties;
public class JaxrHello {
public static void main(String[] args) throws Exception {
ConnectionFactory factory = ConnectionFactory.newInstance();
Properties props = new Properties();
props.setProperty("javax.xml.registry.queryManagerURL",
"http://localhost:8080/registry/uddi/inquiry");
factory.setProperties(props);
Connection conn = factory.createConnection();
RegistryService service = conn.getRegistryService();
System.out.println("Verbunden mit Registry: " + service.getClass().getName());
conn.close();
}
}
XML messages: Jakarta XML RPC
Jakarta XML RPC is an API that makes it possible to implement remote procedure calls (RPC) based on XML messages. It is often used in distributed systems to implement remote method calls.
<dependency> <groupId>jakarta.xml.rpc</groupId> <artifactId>jakarta.xml.rpc-api</artifactId> </dependency>
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
import java.net.URL;
import java.util.Arrays;
public class XmlRpcClientExample {
public static void main(String[] args) throws Exception {
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://localhost:8080/xmlrpc"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
Object result = client.execute("Calculator.add", Arrays.asList(5, 7));
System.out.println("Ergebnis: " + result);
}
}
Web services with SOAP: Jakarta XML Web Services (JAX-WS)
Jakarta XML Web Services (JAX-WS) provides an API that enables the creation of web services based on SOAP messages. In contrast to "jakarta.xml.soap-api", this is at a higher level of abstraction.
<dependency> <groupId>jakarta.xml.ws</groupId> <artifactId>jakarta.xml.ws-api</artifactId> </dependency>
import jakarta.xml.ws.Service;
import javax.xml.namespace.QName;
import java.net.URL;
public class HelloClient {
public static void main(String[] args) throws Exception {
URL wsdlURL = new URL("http://localhost:8080/hello?wsdl");
QName SERVICE_NAME = new QName("http://", "HelloService");
Service service = Service.create(wsdlURL, SERVICE_NAME);
HelloService hello = service.getPort(HelloService.class);
String result = hello.sayHello("Welt");
System.out.println(result);
}
}
This concludes our overview of the Jakarta EE libraries presented. Develop your applications with the Jakarta EE libraries presented and take your projects to the next level. Thank you for your interest in this topic!
Conclusion
The Jakarta EE libraries provide a robust foundation for the development of modern enterprise applications. With technologies ranging from remote procedure calls to security and web services frameworks, they enable developers to realize versatile and scalable solutions. These libraries are not only essential for today's software development, but also future-proof as they are continuously evolving to meet the demands of digital transformation. Use these tools to take your projects to the next level and fully exploit the possibilities of the Jakarta EE platform.
Further links
Jakarta EE is a project of the Eclipse Foundation. The logo is a registered trademark.



