Project Configuration

Back

Loading concept...

Jakarta EE Project Configuration πŸ—οΈ

The Lunchbox Analogy 🍱

Imagine you’re packing a lunchbox for school. You need:

  • The right container (packaging)
  • A label saying what’s inside (coordinates)
  • Instructions for the cafeteria staff (descriptors)
  • Stickers that tell everyone special things about your lunch (annotations)

Jakarta EE projects work the same way! Let’s explore each part.


1. Jakarta EE Packaging πŸ“¦

What is Packaging?

When you finish building with LEGO, you put it in a box to carry it somewhere. In Jakarta EE, packaging means putting your code in a special container so it can run on a server.

The Three Lunchbox Types

graph TD A["Your Code"] --> B{What type?} B --> C["WAR - Web App"] B --> D["JAR - Java Library"] B --> E["EAR - Everything Together"]
Package Full Name What’s Inside Real Example
WAR Web Application Archive Websites, APIs myshop.war
JAR Java Archive Reusable code utils.jar
EAR Enterprise Archive WAR + JAR together bigapp.ear

Simple Example

Think of a pizza shop:

  • JAR = Recipe book (reusable recipes)
  • WAR = The actual pizza shop (serves customers)
  • EAR = The whole franchise (shop + recipes + everything)

2. Maven Coordinates πŸ“

What are Maven Coordinates?

Imagine every house has an address. Maven coordinates are like addresses for code libraries.

When you want to use someone else’s code, you tell Maven exactly where to find it using three things:

groupId    β†’ Who made it (like a company name)
artifactId β†’ What it's called (the project name)
version    β†’ Which version (like v1.0, v2.0)

Real Example

<dependency>
    <groupId>jakarta.platform</groupId>
    <artifactId>jakarta.jakartaee-api</artifactId>
    <version>10.0.0</version>
</dependency>

Reading this address:

  • πŸ“ Made by: jakarta.platform
  • πŸ“ Name: jakarta.jakartaee-api
  • πŸ“ Version: 10.0.0

Your Project’s Own Address

Your project also needs an address! In pom.xml:

<groupId>com.mycompany</groupId>
<artifactId>my-cool-app</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>

3. Deployment Descriptors πŸ“‹

What is a Deployment Descriptor?

Remember the instructions you give a babysitter? β€œFeed the cat at 6pm. No candy before dinner.”

Deployment descriptors are instructions for the server. They tell the server how to run your app.

The Main Descriptor: web.xml

This file lives in src/main/webapp/WEB-INF/web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
         version="6.0">

    <display-name>My Cool App</display-name>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

</web-app>

What Can You Configure?

Setting What It Does Example
welcome-file First page to show index.html
session-timeout How long to remember users 30 minutes
error-page What to show when errors happen error.html

Good News! πŸŽ‰

Modern Jakarta EE apps often don’t need web.xml at all! Annotations (stickers) can do the same job. More on that next!


4. Jakarta EE Annotations ✨

What are Annotations?

Annotations are like magic stickers you put on your code. They tell the server: β€œHey! This code is special. Treat it this way!”

Why Annotations are Amazing

Before annotations (the old way):

  1. Write your code
  2. Write XML configuration
  3. Make sure they match
  4. Fix mistakes
  5. Cry a little

With annotations (the new way):

  1. Write your code with stickers
  2. Done! πŸŽ‰

Common Jakarta EE Annotations

graph TD A["Jakarta EE Annotations"] --> B["@WebServlet"] A --> C["@Entity"] A --> D["@EJB"] A --> E["@Inject"] B --> F["Handle web requests"] C --> G["Database tables"] D --> H["Business logic"] E --> I["Connect things"]

5. Annotations Basics 🏷️

How to Write an Annotation

All annotations start with the @ symbol:

@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
    // Your code here
}

The @WebServlet("/hello") sticker tells the server:

  • β€œThis is a web page handler!”
  • β€œShow it when someone visits /hello”

Anatomy of an Annotation

@AnnotationName(parameter = "value")

Parts:

  • @ β†’ The magic symbol
  • AnnotationName β†’ What kind of sticker
  • (...) β†’ Extra details (optional)

Examples You’ll Use Often

1. Making a Web Page:

@WebServlet("/products")
public class ProductServlet
    extends HttpServlet {
    // Shows product list
}

2. Saving to Database:

@Entity
@Table(name = "customers")
public class Customer {
    @Id
    private Long id;
    private String name;
}

3. Getting Help from Other Code:

@Inject
private CustomerService service;

Annotations vs XML: Quick Compare

Feature Annotations XML
Location Inside your code Separate file
Easy to read βœ… Very easy ❌ Can be messy
Change without recompile ❌ No βœ… Yes
Modern Jakarta EE βœ… Preferred ⚠️ Still works

Putting It All Together 🧩

Let’s see a complete mini-project structure:

my-app/
β”œβ”€β”€ pom.xml                 ← Maven coordinates
β”œβ”€β”€ src/
β”‚   └── main/
β”‚       β”œβ”€β”€ java/
β”‚       β”‚   └── com/myapp/
β”‚       β”‚       └── HelloServlet.java  ← Has @WebServlet
β”‚       └── webapp/
β”‚           └── WEB-INF/
β”‚               └── web.xml  ← Deployment descriptor
└── target/
    └── my-app.war          ← Final package!

The Flow

graph TD A["Write Code"] --> B["Add Annotations"] B --> C["Maven Builds"] C --> D["Creates WAR file"] D --> E["Deploy to Server"] E --> F["App is Running!"]

Key Takeaways 🎯

  1. Packaging = Putting your app in the right container (WAR, JAR, EAR)

  2. Maven Coordinates = Address to find code (groupId:artifactId:version)

  3. Deployment Descriptors = Instructions for the server (web.xml)

  4. Annotations = Magic stickers that configure your code (@WebServlet, @Entity)

  5. Annotations Basics = Start with @, can have parameters, replace most XML


You Did It! πŸŽ‰

You now understand the foundation of every Jakarta EE project. These five concepts are like knowing how to read a map before going on an adventure.

Next time you see:

  • A .war file β†’ You know it’s a web app package!
  • groupId in XML β†’ You know it’s an address!
  • @WebServlet β†’ You know it’s a magic sticker!

You’re ready to build amazing enterprise applications! πŸš€

Loading story...

Story - Premium Content

Please sign in to view this story and start learning.

Upgrade to Premium to unlock full access to all stories.

Stay Tuned!

Story is coming soon.

Story Preview

Story - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.