Back in the days Java Enterprise Edition (EE) with all the Servlets, JSP and JSF, was the recomended way to build enterprise Java Web Apllications, today it’s just called Jakarta EE and under the Eclipse Foundation. Yes, the guys who made the worst IDE ever, JetBrains fans will agree.
For some reason everything that was called Java is now Jakarta, e.g. Jakarta Server Pages. It goes so far that with the Jakarta 9.0 realese the package name (namespace) has changed from javax.*
to jakarta.*
.
Setting up the environment
- JDK 11 or newer.
- Eclipse IDE for Enterprise Java. If you download the standard edition, additional plugins are needed.
- A Server: TomEE 9, Tomcat 10, WildFly 23, Open Liberty 21 or GlassFish 6.
Make sure to add the downloaded server in Eclipse.
Hello Mars Example
- Create a New Maven Project with File → New…
- Add this dependency to
pom.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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ba.draga.dx</groupId>
<artifactId>java-ee-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Java EE 9 Maven Test</name>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>9.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
The jakarta.jakartaee-web-api
dependency should contain all the necessary classes, if this is not the case it can be changed to jakartaee-api
for the full profile.
3. Create a Servlet class.
package ba.dragan.dx;
import java.io.IOException;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@WebServlet("/hello")
public class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getOutputStream().println("Hello Mars");
}
}
4. Run on the Server.
Right click on the project → Run As → Run on Server and select the previously added server.
Yes it’s that easy, for more info visit the Jakarta EE Documentation.