Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

Project and server start

A Jakarta EE application is an ordinary Maven project that is packaged into a WAR file (Web Application Archive): an archive with classes and web pages. A WAR does not run on its own — it is deployed to an application server. The liberty-maven-plugin does this for us: it downloads Open Liberty, puts the WAR into it and starts the server.

Project generator

Open Liberty has an official generator — the start.openliberty.io site. In the form choose Maven, Jakarta EE 11.0, MicroProfile 7.1 and Java 21. You can get the same archive from the terminal:

curl -o blog.zip "https://start.openliberty.io/api/start?a=blog&b=maven&e=11.0&g=com.example&j=21&m=7.1"
unzip blog.zip -d blog
cd blog

The folder now has pom.xml, the Maven wrapper mvnw and a sample server configuration. The package for the course code is com.example.blog.

Structure

PathContents
pom.xmlBuild and dependency description
src/main/java/com/example/blog/Application Java code
src/main/resources/META-INF/Settings: database, MicroProfile Config
src/main/webapp/Static files and Faces pages
src/main/liberty/config/server.xmlOpen Liberty server settings

pom.xml

<!-- 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>com.example</groupId>
    <artifactId>blog</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
 
    <properties>
        <maven.compiler.release>21</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
 
    <dependencies>
        <dependency>
            <groupId>jakarta.platform</groupId>
            <artifactId>jakarta.jakartaee-api</artifactId>
            <version>11.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.microprofile</groupId>
            <artifactId>microprofile</artifactId>
            <version>7.1</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
    </dependencies>
 
    <build>
        <finalName>blog</finalName>
        <plugins>
            <plugin>
                <groupId>io.openliberty.tools</groupId>
                <artifactId>liberty-maven-plugin</artifactId>
                <version>3.12.3</version>
            </plugin>
        </plugins>
    </build>
</project>

The key parts are <packaging>war</packaging> and the jakarta.jakartaee-api dependency with provided scope: the API is needed to compile, and the server supplies the implementation, so the library does not go into the WAR. finalName sets the archive name — target/blog.war.

server.xml

<!-- src/main/liberty/config/server.xml -->
<server description="Blog server">
 
    <featureManager>
        <feature>webProfile-11.0</feature>
        <feature>microProfile-7.1</feature>
    </featureManager>
 
    <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="8080" httpsPort="8443" />
 
    <webApplication contextRoot="/blog" location="blog.war" />
</server>

featureManager lists the server capabilities. webProfile-11.0 includes everything the course needs: servlets, REST, CDI, JPA, transactions, Faces, security. The generator puts the full jakartaee-11.0, but it also brings remote EJBs, which log the error CWWKS9660E when no user registry is configured. The port is changed to 8080, and contextRoot is the start of the application address: http://localhost:8080/blog/.

First page and start

Create the file src/main/webapp/index.html with any HTML, for example a "Blog" heading. Then start the server in development mode:

./mvnw liberty:dev

On Windows use mvnw.cmd liberty:dev. The first start downloads the server and takes a couple of minutes. When everything is ready, the terminal shows these lines (your computer name instead of home-pc):

[INFO] [AUDIT   ] CWWKT0016I: Web application available (default_host): http://home-pc:8080/blog/
[INFO] [AUDIT   ] CWWKF0011I: The defaultServer server is ready to run a smarter planet. The defaultServer server started in 12.920 seconds.

Open http://localhost:8080/blog/ and the browser shows index.html. In development mode the server rebuilds and restarts the application whenever you save a file. To stop it, type q and press Enter.

CommandWhat it does
liberty:devStart with automatic reload
liberty:runPlain start in the terminal
liberty:start / liberty:stopStart in the background and stop

Server logs are in target/liberty/wlp/usr/servers/defaultServer/logs/messages.log.

Common mistake

Opening an address without the contextRoot, for example http://localhost:8080/hello instead of http://localhost:8080/blog/hello. The server returns the Open Liberty page "Context Root Not Found": there is no application on that path. All blog addresses start with /blog.

Thanks for reading!

Donate to the site — we work hard for you.