Tutorial: Your first Jakarta EE application | IntelliJ IDEA (2024)

This tutorial describes how to create a simple Jakarta Enterprise Edition (EE) web application in IntelliJIDEA. The application will include a single JSP page that shows Hello, World! and a link to a Java servlet that also shows Hello, World!.

You will create a new Jakarta EE project using the web application template, tell IntelliJIDEA where your application server is located, then use a run configuration to build the artifact, start the server, and deploy the artifact to it.

Here is what you will need:

IntelliJIDEA Ultimate

Java Enterprise / Jakarta Enterprise development is not supported in the free IntelliJIDEA Community Edition. For more information, refer to IntelliJIDEA Ultimate vs IntelliJIDEA Community Edition

Relevant plugins

By default, the following necessary plugins are bundled and enabled in IntelliJIDEA Ultimate. If something does not work, make sure that the following plugins are enabled:

  • Jakarta EE Platform

  • Jakarta EE: Application Servers

  • Jakarta EE: Web/Servlets

  • Tomcat and TomEE

Install and enable the GlassFish plugin as described in Install plugins.

Java SE Development Kit (JDK) version 1.8 or later

You can get the JDK directly from IntelliJIDEA as described in Java Development Kit (JDK) or download and install it manually, for example: Oracle JDK or OpenJDK.

Tomcat

The Tomcat application server version 7 or later.

GlassFish

The GlassFish application server version 4.0 or later. You can get the latest release from the official repository. The Web Profile subset should be enough for the purposes of this tutorial.

Web browser

You will need a web browser to view your web application.

Create a new Jakarta EE project

IntelliJIDEA includes a dedicated wizard for creating Jakarta Enterprise projects based on various Jakarta EE implementations. In this tutorial, we will create a simple web application.

  1. In the main menu, go to File | New | Project.

  2. In the New Project dialog, select Jakarta EE.

  3. Enter a name for your project: JakartaEEHelloWorld.

  4. Select the Web application template, Maven as a build tool, and use Oracle OpenJDK 17 as the project SDK. Don't select or add an application server, we will do it later.

    Click Next to continue.

    Tutorial: Your first Jakarta EE application | IntelliJIDEA (1)
  5. In the Version field, select Jakarta EE 11 because that's what Tomcat 11 used in this tutorial is compatible with.

    In the Version field, select Jakarta EE 9.1 because that's what GlassFish 6.2.5 used in this tutorial is compatible with.

    In the Dependencies list, you can see that the web application template includes only the Servlet framework under Specifications.

    Tutorial: Your first Jakarta EE application | IntelliJIDEA (2)
    Tutorial: Your first Jakarta EE application | IntelliJIDEA (3)
  6. Click Create.

Explore the default project structure

IntelliJIDEA creates a project with some boilerplate code that you can build and deploy successfully.

  • pom.xml is the Project Object Model with Maven configuration information, including dependencies and plugins necessary for building the project.

    <?xml version="1.0" encoding="UTF-8"?> <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>org.example</groupId> <artifactId>JakartaEEHelloWorld</artifactId> <version>1.0-SNAPSHOT</version> <name>JakartaEEHelloWorld</name> <packaging>war</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.target>21</maven.compiler.target> <maven.compiler.source>21</maven.compiler.source> <junit.version>5.11.0-M2</junit.version> </properties> <dependencies> <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>6.1.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.4.0</version> </plugin> </plugins> </build> </project>

    <?xml version="1.0" encoding="UTF-8"?> <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>org.example</groupId> <artifactId>JakartaEEHelloWorld</artifactId> <version>1.0-SNAPSHOT</version> <name>JakartaEEHelloWorld</name> <packaging>war</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.target>11</maven.compiler.target> <maven.compiler.source>11</maven.compiler.source> <junit.version>5.9.2</junit.version> </properties> <dependencies> <dependency> <groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>5.0.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.3.2</version> </plugin> </plugins> </build> </project>

  • index.jsp is the starting page of your application that opens when you access the root directory URL. It renders Hello World! and a link to /hello-servlet.

    <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <!DOCTYPE html> <html> <head> <title>JSP - Hello World</title> </head> <body> <h1><%= "Hello World!" %> </h1> <p/> <a href="hello-servlet">Hello Servlet</a> </body> </html>

  • The HelloServlet class extends HttpServlet and is annotated with @WebServlet. It processes requests to /hello-servlet: a GET request returns HTML code that renders Hello World!.

    package com.example.demo; import java.io.*; import javax.servlet.http.*; import javax.servlet.annotation.*; @WebServlet(value = "/hello-servlet") public class HelloServlet extends HttpServlet { private String message; public void init() { message = "Hello World!"; } public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/html"); // Hello PrintWriter out = response.getWriter(); out.println("<html><body>"); out.println("<h1>" + message + "</h1>"); out.println("</body></html>"); } public void destroy() { } }

Use the Project tool window to browse and open files in your project or press Ctrl+Shift+N and type the name of the file.

Configure the application server

Let IntelliJIDEA know where the GlassFish Tomcat application server is located.

  1. Press Ctrl+Alt+S to open settings and then select Build, Execution, Deployment | Application Servers.

  2. Click Tutorial: Your first Jakarta EE application | IntelliJIDEA (4) and select Glassfish Server Tomcat.

  3. Specify the path to the GlassFish Tomcat server install location. IntelliJIDEA detects and sets the name and version appropriately.

    Tutorial: Your first Jakarta EE application | IntelliJIDEA (5)
    Tutorial: Your first Jakarta EE application | IntelliJIDEA (6)

Create a run configuration

IntelliJIDEA needs a run configuration to build the artifacts and deploy them to your application server.

  1. In the main menu, go to Run | Edit Configurations.

  2. In the Run/Debug Configurations dialog, click Tutorial: Your first Jakarta EE application | IntelliJIDEA (7), expand the Glassfish Server Tomcat Server node, and select Local.

  3. Fix any warnings that appear at the bottom of the run configuration settings dialog.

    Tutorial: Your first Jakarta EE application | IntelliJIDEA (8)

    Most likely, you will need to fix the following:

    • On the Server tab, set the Server Domain to domain1.

    • On the Deployment tab, add the artifact that you want to deploy: JakartaEEHelloWorld:war exploded

  4. On the Server tab, set the URL to point to the root resource:

    http://localhost:8080/JakartaEEHelloWorld_war_exploded/

    http://localhost:8080/JakartaEEHelloWorld-1.0-SNAPSHOT/

    Tutorial: Your first Jakarta EE application | IntelliJIDEA (9)
    Tutorial: Your first Jakarta EE application | IntelliJIDEA (10)
  5. Click OK to save the run configuration.

  6. To run the configuration, press Alt+Shift+F10 and select the created application server configuration.

    Alternatively, if you have your run configuration selected in the main toolbar at the top, you can click Tutorial: Your first Jakarta EE application | IntelliJIDEA (11) in the main toolbar or press Shift+F10 to run it.

This run configuration builds the artifacts, then starts the GlassFish Tomcat server, and deploys the artifacts to the server. You should see the corresponding output in the Services tool window.

Tutorial: Your first Jakarta EE application | IntelliJIDEA (12)
Tutorial: Your first Jakarta EE application | IntelliJIDEA (13)

Once this is done, IntelliJIDEA opens the specified URL in your web browser.

Tutorial: Your first Jakarta EE application | IntelliJIDEA (14)

If not, try opening the URL yourself: http://localhost:8080/JakartaEEHelloWorld_war_exploded/ http://localhost:8080/JavaEEHelloWorld-1.0-SNAPSHOT/

Modify the application

Whenever you change the source code of the application, you can restart the run configuration to see the changes. But this is not always necessary, especially when you can't restart the server. Most of the changes are minor and don't require rebuilding the artifacts, restarting the server, and so on. Let's change the JSP page of the application.

  1. Open index.jsp and change the greeting from Hello World to A better greeting.

  2. In the Services tool window, click Tutorial: Your first Jakarta EE application | IntelliJIDEA (15) or press Ctrl+F10.

  3. In the Update dialog, select Update resources because the JSP page is a static resource. Click OK.

  4. Refresh the application URL in your web browser to see the new string: A better greeting.

You can configure the default update action in the run configuration settings: go to Run | Edit Configurations in the main menu. Change the On 'Update' action option under the Server tab of the GlassFish Tomcat run configuration settings.

Tutorial: Your first Jakarta EE application | IntelliJIDEA (16)
Tutorial: Your first Jakarta EE application | IntelliJIDEA (17)

With the On frame deactivation option, you can configure to update your resources and classes without redeploying and restarting the server whenever you change focus from IntelliJIDEA. In this case, you won't even have to use the Update Application action, just switch to your web browser and refresh the page.

Package the application into a WAR and deploy it on a running server

In the previous steps, we deployed the application using an exploded artifact, where all files are uncompressed. This is useful during the first stages of development because it allows you to update individual resources and classes without redeploying. When you are happy with your application and ready to share it with others by deploying to a remote server, it is better to use the compressed web archive (WAR) format.

Let's add a Remote GlassFish Remote Tomcat run configuration to deploy the WAR artifact to a running server. This assumes that you did not terminate the running server from the previous steps.

  1. In the main menu, go to Run | Edit Configurations.

  2. In the Run/Debug Configurations dialog, click Tutorial: Your first Jakarta EE application | IntelliJIDEA (18), expand the GlassFish Server Tomcat node, and select Remote.

  3. Change the name of this run configuration to distinguish it, for example: Remote GlassFish 6.2.5 Remote Tomcat 10.1.5.

  4. Open the Deployment tab, click Tutorial: Your first Jakarta EE application | IntelliJIDEA (19) above the table of artifacts to deploy, and select Artifact. Select the JakartaEEHelloWorld:war artifact and click OK.

    Tutorial: Your first Jakarta EE application | IntelliJIDEA (20)
    Tutorial: Your first Jakarta EE application | IntelliJIDEA (21)
  5. Click OK to save the remote run configuration.

  6. Open index.jsp and change the greeting to Hello from WAR!.

  7. Select the new run configuration in the main toolbar and click Tutorial: Your first Jakarta EE application | IntelliJIDEA (22) or press Shift+F10.

    Tutorial: Your first Jakarta EE application | IntelliJIDEA (23)

    Tutorial: Your first Jakarta EE application | IntelliJIDEA (24)

The new configuration builds the WAR artifact and deploys it to the running server. Refresh the URL and see the new greeting: Hello from WAR!

Troubleshooting

Compatibility with Jakarta EE

If you get a 404 error, make sure you have selected the Jakarta EE specification version that is compatible with your version of GlassFish when creating the project.

For more information, refer to the GlassFish version compatibility.

Unable to connect to Tomcat

If you see an error message like Unable to connect to the localhost:1099 when trying to deploy the application on a remote Tomcat server, try these steps:

  • Make sure the Tomcat server is running. For example, launch the local Tomcat run configuration described above.

  • Configure JMX authentication or (if it's not a production environment), disable it by passing the -Dcom.sun.management.jmxremote.authenticate=false VM option before running the server on which you want to deploy the application.

Older IntelliJIDEA versions

If you are using IntelliJIDEA version 2020.2.2 or earlier, the New Project wizard will not add all of the necessary dependencies required for Tomcat. In this case, open pom.xml and add the following dependencies:

<dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> <version>2.31</version> </dependency> <dependency> <groupId>org.glassfish.jersey.inject</groupId> <artifactId>jersey-hk2</artifactId> <version>2.31</version> </dependency>

For example, in version 2020.2.3, the generated pom.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?> <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>RestTomcatHelloWorld</artifactId> <version>1.0-SNAPSHOT</version> <name>RestTomcatHelloWorld</name> <packaging>war</packaging> <properties> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> <junit.version>5.6.2</junit.version> </properties> <dependencies> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> <version>2.1.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.glassfish.jersey.containers</groupId> <artifactId>jersey-container-servlet</artifactId> <version>2.31</version> </dependency> <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> <version>2.31</version> </dependency> <dependency> <groupId>org.glassfish.jersey.inject</groupId> <artifactId>jersey-hk2</artifactId> <version>2.31</version> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>2.31</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.3.0</version> </plugin> </plugins> </build> </project>

What next?

In this tutorial, we created and deployed a simple Jakarta EE application. To extend this knowledge, you can create a RESTful web service as described in Tutorial: Your first RESTful web service.

Last modified: 09 August 2024

Java EnterpriseEnterprise application support

Tutorial: Your first Jakarta EE application | IntelliJ IDEA (2024)

FAQs

How to create a Jakarta EE project? ›

Create a new Jakarta EE project
  1. In the main menu, go to File | New | Project.
  2. In the New Project dialog, select Jakarta EE.
  3. Enter a name for your project: JakartaEEHelloWorld .
  4. Select the Web application template, Maven as a build tool, and use Oracle OpenJDK 17 as the project SDK.
Aug 9, 2024

How to use Jakarta EE? ›

Starting the Administration Console. To administer GlassFish Server and manage users, resources, and Jakarta EE applications, use the Administration Console tool. GlassFish Server must be running before you invoke the Administration Console. To start the Administration Console, open a browser at http://localhost:4848/.

How to get started with IntelliJ IDEA? ›

First steps
  1. Install IntelliJ IDEA. Install and run IntelliJ IDEA for the first time.
  2. Create your first Java application. Create, run, and package a simple Java application in IntelliJ IDEA.
  3. Learn IDE features. ...
  4. Learn keyboard shortcuts. ...
  5. Install plugins. ...
  6. Configure your project. ...
  7. Write the source code. ...
  8. Get support and assistance.

Can I use IntelliJ Community for Java EE? ›

IntelliJ IDEA provides support for developing enterprise Java applications based on Jakarta EE (formerly known as Java EE).

Which companies use Jakarta EE? ›

Companies Currently Using Jakarta EE
Company NameWebsiteSub Level Industry
Lockheed Martinlockheedmartin.comAerospace & Defense
PHPphp.netSoftware Manufacturers
Ehrhardt + Partner Groupepg.comSoftware Development & Technical Consulting
SHS VIVEON AGshs-viveon.comSoftware Development & Technical Consulting
2 more rows

What is the introduction of Jakarta EE? ›

Jakarta EE, formerly Java Platform, Enterprise Edition (Java EE) and Java 2 Platform, Enterprise Edition (J2EE), is a set of specifications, extending Java SE with specifications for enterprise features such as distributed computing and web services.

Should I use Jakarta EE or spring? ›

Java EE offers a standardized, comprehensive approach to application development, while Spring provides a more flexible and modular framework that many find to be more agile and easier to work with.

How popular is Jakarta EE? ›

Spring Boot wins, Jakarta EE is second, Quarkus third, and Micronaut fourth. The overall number of developer ads is down in 2023. Spring Boot has lost 13% in the last year, dropping to a 5.1:1 lead over Jakarta EE. The new kids, Quarkus and Micronaut, at #3 and #4, saw their rebound continue.

What is the difference between Java EE and Jakarta EE? ›

While Java EE supported distributed computing and web services, Jakarta EE adopted cloud-native principles such as containerization and orchestration. This shift enables developers to create scalable, resilient, and portable applications that can run seamlessly in modern cloud environments.

Is IntelliJ good for beginners? ›

Ultimately, it's up to you which IDE you prefer- they both have pros and cons. IntelliJ is probably the best choice for beginners, but Eclipse may be better if you need more power and flexibility. Both IDEs are popular Java development environments, and they have a lot of similarities but also some key differences.

Do I need a license to use IntelliJ IDEA? ›

IntelliJ IDEA Community Edition is free and can be used without any license. You cannot upgrade to IntelliJ IDEA Ultimate: download and install it separately as described in Install IntelliJ IDEA.

How do I write the first code in IntelliJ? ›

New Java project with onboarding tips
  1. Launch IntelliJ IDEA. If the Welcome screen opens, click New Project. ...
  2. From the list on the left, select New Project. ...
  3. Select the Add sample code checkbox and enable Generate code with onboarding tips.
  4. Click Create.
Aug 9, 2024

Is IntelliJ no longer free? ›

Community Edition is free and open-source, licensed under Apache 2.0. It provides all the basic features for JVM and Android development. IntelliJ IDEA Ultimate is commercial, distributed with a 30-day trial period.

Is IntelliJ community good enough? ›

Conclusion. Choosing between IntelliJ IDEA Community Edition and IntelliJ IDEA Ultimate largely depends on your specific needs. For beginners, students, or developers mainly focusing on Java or Kotlin, the Community Edition's comprehensive array of features provides an efficient, cost-effective solution.

What is Jakarta EE 10? ›

The Jakarta EE is an open-source framework for developing web applications in Java or, as currently stated, cloud-native Java. Previously known as Java EE (Java Enterprise Edition), developed and maintained by Oracle through JCP (Java Community Process).

How to create a project in J2EE? ›

In the Java™ EE perspective, click File > New > Project. In the New Project Wizard, select J2EE > Enterprise Application Project and click Next. In the Project Name field, type a name for the new project.

How do I create an EJB project? ›

Creating EJB projects
  1. In the Java EE perspective, select File > New > Other.
  2. In the New Project Wizard, select EJB > EJB Project and click Next.
  3. In the Project Name field, type a name for the EJB project.
  4. Optional: To use a different workspace directory for your EJB project, modify the settings for Project contents.

Is Jakarta EE the same as Java EE? ›

Actually, the Eclipse Foundation legally had to rename Java EE. That's because Oracle has the rights over the “Java” brand. So to choose the new name, the community voted and picked: Jakarta EE. In a certain way, it's still JEE.

How to create a new project in Java EE Eclipse? ›

Procedure
  1. Open Eclipse.
  2. Click Workbench.
  3. Click Window > Open Perspective > Java to open the Java perspective.
  4. Click File > Java Project to create a new Java project.
  5. Enter a Project name.
  6. Click Finish.
  7. Right-click the new project, then click Properties.
  8. On the Properties window, click Java Build Path.

Top Articles
Top 27 Free Sports Streaming Sites for August 2024 (No Buffering)
Khalid Sheikh Mohammed, accused as the main plotter of 9/11 attacks, agrees to plead guilty
Evil Dead Rise Review - IGN
Houses For Sale 180 000
Swgoh Darth Vader Mods
Smoke Terminal Waterbury Photos
Seacrest 7 Piece Dining Set
Local Dog Boarding Kennels Near Me
Msu Ro
Pebble Keys 2 K380s Bluetooth Keyboard | Logitech
Maine Coon Craigslist
Voy Pageant Discussion
Best Charter Schools Tampa
When His Eyes Opened Chapter 3096
Does the MLB allow gambling? Here's what to know about League Rule 21
Car Complaints Toyota
Rub Rating Louisville
Ixl Spring Branch
Dominion Post Obituaries Morgantown
Wild Fork Foods Login
Monahan's By The Cove Charlestown Menu
Aldine Isd Pay Scale 23-24
Slmd Skincare Appointment
Broyhill Gazebo Instructions
T-Zell-Leukämie mit großen granulären Lymphozyten - Altmeyers Enzyklopädie - Fachbereich Innere Medizin
Mark Rosen announces his departure from WCCO-TV after 50-year career
When Is Meg Macnamara Due
Kagtwt
12 30 Pacific Time
Circuit Court Evanston Wy
Calculating R-Value: How To Calculate R-Value? (Formula + Units)
Ancestors The Humankind Odyssey Wikia
Petco Clinic Hours
Philasd Zimbra
Strange World Showtimes Near Amc Hoffman Center 22
Joe Bartlett Wor Salary
Claudia Capertoni Only Fans
Get Over It Stables
Goose Band Setlists
Meat Grinders At Menards
Curaleaf Announces Majority Stake and Forms Strategic Partnership with Germany's Four 20 Pharma, a Fully EU-GMP & GDP Licensed Producer and Distributor of Medical Cannabis
1984 Argo JM16 GTP for sale by owner - Holland, MI - craigslist
Ace Adventure Resort Discount Code 2023
Bonbast قیمت ارز
Fgo Spirit Root
50 Shades Of Grey Movie 123Movies
Subway Surfers Unblocked Games World
Bitlife Tyrone's
Ucf Cost Calculator
Apartments for Rent in Buellton, CA - Home Rentals | realtor.com®
Corn And Tater Fest 2023
Senna Build Guides :: League of Legends Strategy Builds, Runes, Items, and Abilities :: Patch 14.18
Latest Posts
Article information

Author: Maia Crooks Jr

Last Updated:

Views: 6591

Rating: 4.2 / 5 (43 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Maia Crooks Jr

Birthday: 1997-09-21

Address: 93119 Joseph Street, Peggyfurt, NC 11582

Phone: +2983088926881

Job: Principal Design Liaison

Hobby: Web surfing, Skiing, role-playing games, Sketching, Polo, Sewing, Genealogy

Introduction: My name is Maia Crooks Jr, I am a homely, joyous, shiny, successful, hilarious, thoughtful, joyous person who loves writing and wants to share my knowledge and understanding with you.