Book Image

Jakarta EE Cookbook - Second Edition

By : Elder Moraes
Book Image

Jakarta EE Cookbook - Second Edition

By: Elder Moraes

Overview of this book

Jakarta EE is widely used around the world for developing enterprise applications for a variety of domains. With this book, Java professionals will be able to enhance their skills to deliver powerful enterprise solutions using practical recipes. This second edition of the Jakarta EE Cookbook takes you through the improvements introduced in its latest version and helps you get hands-on with its significant APIs and features used for server-side development. You'll use Jakarta EE for creating RESTful web services and web applications with the JAX-RS, JSON-P, and JSON-B APIs and learn how you can improve the security of your enterprise solutions. Not only will you learn how to use the most important servers on the market, but you'll also learn to make the best of what they have to offer for your project. From an architectural point of view, this Jakarta book covers microservices, cloud computing, and containers. It allows you to explore all the tools for building reactive applications using Jakarta EE and core Java features such as lambdas. Finally, you'll discover how professionals can improve their projects by engaging with and contributing to the community. By the end of this book, you'll have become proficient in developing and deploying enterprise applications using Jakarta EE.
Table of Contents (14 chapters)

To get the most out of this book

You should be familiar with application development and you need to have at least basic knowledge of Java and Jakarta EE. Basic knowledge of cloud computing and web services is also assumed.

Software/hardware covered in the book

OS requirements

Open JDK 8 or superior

Linux/macOS/Windows

Maven 3.5

Linux/macOS/Windows

Eclipse GlassFish 5.1

Linux/macOS/Windows

Docker CE 18

Linux/macOS/Windows

Git SCM 2.16

Linux/macOS/Windows

If when trying to run any of the code in this book you got a message saying that the "address is already in use" or something like it, you probably have an other service/application using the same port that the example is trying to use. Closing it will fix this issue.

Jakarta EE 9 is on the way – what now?

By the time this second edition is released, we will just be a few months away from the release of Jakarta EE 9! Because of this, you may be wondering, "why not publish the book when 9 is alive and kicking?".

Good question! And the answer is equally clear: because no APIs/features will be changing in this release. So, what's changed that would justify a new release?

Because of one thing in the Jakarta EE field known as big bang. If you've been following Jakarta EE for a while now, you should be aware of it. If not, let me quickly explain it to you.

Due to Java EE being transferred from Oracle to Eclipse Foundation, it was rebranded to Jakarta EE, and due to this, we had the Jakarta EE 8 release. That's why we have the second edition of this book!

As part of the branding and intellectual property process, another thing needed to be changed: the javax namespaces.

The following examples have been taken from this very book, and all of them use the javax namespace:

import javax.ws.rs.core.Application;
import javax.ws.rs.container.AsyncResponse;
import javax.ejb.EJB;
import javax.validation.constraints.Size;

So, all the APIs under Jakarta EE have to change their namespaces from javax to jakarta. This same list in Jakarta EE 9 will look like this:

import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.container.AsyncResponse;
import jakarta.ejb.EJB;
import jakarta.validation.constraints.Size;

Since this book was written to help you deliver the most incredible applications using Jakarta EE 8, I need to answer the following, and most important, question: how does this change affect you and/or your code if you migrate from 8 to 9?

The simple and quick answer is that your code/project will break. Period.

This isn't as bad as it sounds. At the end of the day, Jakarta EE has a huge community of developers around the world (probably one of the biggest communities), and most of them are developers like you that will face these same problems if there's no way out.

So, yes, you'll need to change the imports for all the classes in your project that use the javax namespace. And no, you won't need to do this manually (unless you want to).

While I'm writing this, there is already one tool that is being developed by the Apache Tomcat folks. You can try it out and follow the project for more information at https://github.com/apache/tomcat-jakartaee-migration.

I'm pretty sure that even more tools will become available soon. Stay tuned!

For more information about the big bang, you can read this amazing blog post by Mike Milinkovich: https://eclipse-foundation.blog/2020/01/16/moving-forward-with-jakarta-ee-9/.

Download the example code files

You can download the example code files for this book from your account at www.packtpub.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/eldermoraes/javaee8-cookbook. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781838642884_ColorImages.pdf .

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Then, two key methods from SseResource do their work."

A block of code is set as follows:

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>

Any command-line input or output is written as follows:

Info:   destroy

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "We defined the security rules and roles through our code (the program). There's another approach called declarative security."

Warnings or important notes appear like this.
Tips and tricks appear like this.