Skip to content

Commit 511325e

Browse files
committed
chore: bump to Jakarta EE 11
1 parent a3ce5e3 commit 511325e

File tree

14 files changed

+125
-112
lines changed

14 files changed

+125
-112
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v4
17-
- name: Set up JDK 17
17+
- name: Set up JDK
1818
uses: actions/setup-java@v4
1919
with:
20-
java-version: 17
21-
distribution: 'zulu'
20+
java-version: "21"
21+
distribution: "zulu"
2222
cache: "maven"
2323
- name: Build with Maven
2424
run: mvn clean package --file pom.xml

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
[![build](https://github.com/hantsy/jakartaee-mvc-sample/actions/workflows/build.yml/badge.svg)](https://github.com/hantsy/jakartaee-mvc-sample/actions/workflows/build.yml)
44

5-
As an alternative to Jakarta Faces, which is used to build web UIs with components, the [Jakarta MVC](https://www.mvc-spec.org/) spec is similar to traditional MVC frameworks, such as Apache Struts and Spring MVC, and provides the capability to build action-based web applications.
5+
As an alternative to Jakarta Faces, which is used to build web UIs with components, the [Jakarta MVC](https://www.mvc-spec.org/) spec is similar to traditional MVC frameworks, such as Apache Struts and Spring MVC, and enables the development of action-based web applications.
66

7-
The repository has already been upgraded to Jakarta EE 10.
7+
The repository has already been upgraded to Jakarta EE 11.
88

9-
* The Jakarta EE 8-based code was archived and also tagged with [v1.0 tag](https://github.com/hantsy/jakartaee-mvc-sample/releases/tag/v1.0).
9+
* For the Jakarta EE 10 version, check the release [Archive for Jakarta EE 10](https://github.com/hantsy/jakartaee-mvc-sample/releases/tag/ee10).
10+
* For the old Jakarta EE 8 version, check the release [Archive for Jakarta EE 8](https://github.com/hantsy/jakartaee-mvc-sample/releases/tag/v1.0).
1011

1112
[Jakarta MVC](https://www.mvc-spec.org/) is based on the existing JAX-RS specs, reuses the JAX-RS APIs, and adds additional APIs for specific *action* features.
1213

@@ -16,6 +17,9 @@ The repository has already been upgraded to Jakarta EE 10.
1617
* Resteasy( Wildfly)
1718
* <del>Apache CXF</del> MVC 2.0 remove CXF support.
1819

20+
> [!WARNING]
21+
> Jakarta MVC 3.0/Eclipse Krazo 4.0 removed Faclets as the view engine, and switched to Jakarta Pages as the default view engine, but it lacks a `Composite View Pattern` to layout views. I restored the `FaceletsViewEngine` that was deleted in the Eclipse Krazo 4.0, and reused the former Facelets views.
22+
1923
![home](./home.png)
2024

2125
![task list](./tasks.png)

pom.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<properties>
1515
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16-
<maven.compiler.release>17</maven.compiler.release>
16+
<maven.compiler.release>21</maven.compiler.release>
1717
<failOnMissingWebXml>false</failOnMissingWebXml>
1818

1919
<!-- Maven Plugins -->
@@ -27,10 +27,10 @@
2727

2828
<!-- Jakarta EE API -->
2929
<jakartaee-api.version>10.0.0</jakartaee-api.version>
30-
<jakarta.mvc-api.version>2.1.0</jakarta.mvc-api.version>
30+
<jakarta.mvc-api.version>3.0.0</jakarta.mvc-api.version>
3131

3232
<!-- Eclipse Krazo -->
33-
<krazo.version>3.0.1</krazo.version>
33+
<krazo.version>4.0.0</krazo.version>
3434

3535
<!-- Arquillian BOM -->
3636
<arquillian.version>1.10.0.Final</arquillian.version>
@@ -47,10 +47,10 @@
4747
<hamcrest.version>3.0</hamcrest.version>
4848

4949
<!-- Glassfish server -->
50-
<glassfish.version>7.0.24</glassfish.version>
50+
<glassfish.version>8.0.0</glassfish.version>
5151
<arquillian-glassfish.version>7.0.14</arquillian-glassfish.version>
52-
<jersey.version>3.1.0</jersey.version>
53-
<eclipselink.version>4.0.9</eclipselink.version>
52+
<jersey.version>4.0.0</jersey.version>
53+
<eclipselink.version>5.0.0-B13</eclipselink.version>
5454

5555
<!-- By default, skip tests -->
5656
<skipTests>true</skipTests>
@@ -117,6 +117,7 @@
117117
<groupId>jakarta.mvc</groupId>
118118
<artifactId>jakarta.mvc-api</artifactId>
119119
<version>${jakarta.mvc-api.version}</version>
120+
<scope>provided</scope>
120121
</dependency>
121122
<!-- https://mvnrepository.com/artifact/org.eclipse.krazo/krazo-jersey -->
122123
<dependency>
@@ -227,6 +228,7 @@
227228
<dependency>
228229
<groupId>org.junit.jupiter</groupId>
229230
<artifactId>junit-jupiter</artifactId>
231+
<scope>test</scope>
230232
</dependency>
231233

232234
</dependencies>
@@ -328,7 +330,7 @@
328330
<version>${cargo-maven3-plugin.version}</version>
329331
<configuration>
330332
<container>
331-
<containerId>glassfish7x</containerId>
333+
<containerId>glassfish8x</containerId>
332334
<zipUrlInstaller>
333335
<url>
334336
https://github.com/eclipse-ee4j/glassfish/releases/download/${glassfish.version}/glassfish-${glassfish.version}.zip
@@ -338,7 +340,7 @@
338340
</container>
339341
<configuration>
340342
<!-- the configuration used to deploy -->
341-
<home>${project.build.directory}/glassfish7x-home</home>
343+
<home>${project.build.directory}/glassfish8x-home</home>
342344
<properties>
343345
<cargo.remote.password></cargo.remote.password>
344346
<cargo.glassfish.removeDefaultDatasource>true
@@ -409,7 +411,7 @@
409411
--add-opens java.base/java.lang=ALL-UNNAMED
410412
</argLine>
411413
<environmentVariables>
412-
<GLASSFISH_HOME>${project.build.directory}/glassfish7</GLASSFISH_HOME>
414+
<GLASSFISH_HOME>${project.build.directory}/glassfish8</GLASSFISH_HOME>
413415
</environmentVariables>
414416
</configuration>
415417
</plugin>

src/main/java/com/example/Bootstrap.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22

33
import com.example.domain.Task;
44
import com.example.domain.TaskRepository;
5+
import jakarta.enterprise.context.ApplicationScoped;
6+
import jakarta.enterprise.event.Observes;
7+
import jakarta.enterprise.event.Startup;
8+
import jakarta.inject.Inject;
9+
import jakarta.transaction.Transactional;
10+
511
import java.util.logging.Level;
612
import java.util.logging.Logger;
713
import java.util.stream.Collectors;
814
import java.util.stream.Stream;
9-
import jakarta.annotation.PostConstruct;
10-
import jakarta.ejb.Singleton;
11-
import jakarta.ejb.Startup;
12-
import jakarta.inject.Inject;
1315

14-
/**
15-
*
16-
* @author hantsy
17-
*/
18-
@Startup
19-
@Singleton
16+
@ApplicationScoped
17+
@Transactional
2018
public class Bootstrap {
2119

2220
@Inject
@@ -25,8 +23,7 @@ public class Bootstrap {
2523
@Inject
2624
TaskRepository taskRepository;
2725

28-
@PostConstruct
29-
public void init() {
26+
public void init(@Observes Startup startup) {
3027
LOG.log(Level.INFO, "bootstraping application...");
3128

3229
Stream.of("first", "second")
@@ -38,7 +35,6 @@ public void init() {
3835
return task;
3936
})
4037
.map(data -> taskRepository.save(data))
41-
.collect(Collectors.toList())
4238
.forEach(task -> LOG.log(Level.INFO, " task saved: {0}", new Object[]{task}));
4339
}
4440
}

src/main/java/com/example/config/MvcConfig.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package com.example.config;
22

3+
import jakarta.mvc.engine.ViewEngine;
34
import jakarta.ws.rs.ApplicationPath;
45
import jakarta.ws.rs.core.Application;
56

7+
import java.util.HashMap;
8+
import java.util.Map;
9+
610
@ApplicationPath("mvc")
711
public class MvcConfig extends Application {
812

@@ -33,14 +37,16 @@ public class MvcConfig extends Application {
3337
*
3438
*
3539
* ViewEngine.VIEW_FOLDER
36-
*
40+
* <p>
3741
* Csrf.CSRF_PROTECTION
38-
*
42+
* <p>
3943
* Csrf.CSRF_HEADER_NAME
40-
*
41-
*
42-
*
43-
* @Override public Map<String, Object> getProperties() { final Map<String, Object> map = new HashMap<>();
44-
* map.put(ViewEngine.VIEW_FOLDER, "/jsp/"); return map; }
4544
*/
45+
46+
// @Override
47+
// public Map<String, Object> getProperties() {
48+
// final Map<String, Object> map = new HashMap<>();
49+
// map.put(ViewEngine.VIEW_EXTENSION, "xhtml");
50+
// return map;
51+
// }
4652
}

src/main/java/com/example/domain/Task.java

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -129,48 +129,14 @@ public void setLastModifiedDate(LocalDateTime lastModifiedDate) {
129129
}
130130

131131
@Override
132-
public int hashCode() {
133-
int hash = 7;
134-
hash = 67 * hash + Objects.hashCode(this.id);
135-
hash = 67 * hash + Objects.hashCode(this.name);
136-
hash = 67 * hash + Objects.hashCode(this.description);
137-
hash = 67 * hash + Objects.hashCode(this.status);
138-
hash = 67 * hash + Objects.hashCode(this.createdDate);
139-
hash = 67 * hash + Objects.hashCode(this.lastModifiedDate);
140-
return hash;
132+
public boolean equals(Object o) {
133+
if (!(o instanceof Task task)) return false;
134+
return Objects.equals(name, task.name);
141135
}
142136

143137
@Override
144-
public boolean equals(Object obj) {
145-
if (this == obj) {
146-
return true;
147-
}
148-
if (obj == null) {
149-
return false;
150-
}
151-
if (getClass() != obj.getClass()) {
152-
return false;
153-
}
154-
final Task other = (Task) obj;
155-
if (!Objects.equals(this.name, other.name)) {
156-
return false;
157-
}
158-
if (!Objects.equals(this.description, other.description)) {
159-
return false;
160-
}
161-
if (!Objects.equals(this.id, other.id)) {
162-
return false;
163-
}
164-
if (this.status != other.status) {
165-
return false;
166-
}
167-
if (!Objects.equals(this.createdDate, other.createdDate)) {
168-
return false;
169-
}
170-
if (!Objects.equals(this.lastModifiedDate, other.lastModifiedDate)) {
171-
return false;
172-
}
173-
return true;
138+
public int hashCode() {
139+
return Objects.hashCode(name);
174140
}
175141

176142
@PrePersist

src/main/java/com/example/domain/TaskRepository.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
package com.example.domain;
22

3-
import java.util.List;
4-
import jakarta.ejb.Stateless;
3+
import jakarta.enterprise.context.ApplicationScoped;
4+
import jakarta.inject.Inject;
55
import jakarta.persistence.EntityManager;
6-
import jakarta.persistence.PersistenceContext;
76
import jakarta.persistence.TypedQuery;
87
import jakarta.persistence.criteria.CriteriaBuilder;
98
import jakarta.persistence.criteria.CriteriaQuery;
109
import jakarta.persistence.criteria.Root;
10+
import jakarta.transaction.Transactional;
11+
12+
import java.util.List;
1113

1214
/**
1315
*
1416
* @author hantsy
1517
*/
16-
@Stateless
18+
@ApplicationScoped
19+
@Transactional
1720
public class TaskRepository {
1821

19-
@PersistenceContext
22+
@Inject
2023
EntityManager em;
2124

2225
public Task findById(Long id) {

src/main/java/com/example/web/TaskForm.java

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,41 +50,22 @@ public void setDescription(String description) {
5050
}
5151

5252
@Override
53-
public int hashCode() {
54-
int hash = 7;
55-
hash = 61 * hash + Objects.hashCode(this.id);
56-
hash = 61 * hash + Objects.hashCode(this.name);
57-
hash = 61 * hash + Objects.hashCode(this.description);
58-
return hash;
53+
public boolean equals(Object o) {
54+
if (!(o instanceof TaskForm taskForm)) return false;
55+
return Objects.equals(id, taskForm.id) && Objects.equals(name, taskForm.name) && Objects.equals(description, taskForm.description);
5956
}
6057

6158
@Override
62-
public boolean equals(Object obj) {
63-
if (this == obj) {
64-
return true;
65-
}
66-
if (obj == null) {
67-
return false;
68-
}
69-
if (getClass() != obj.getClass()) {
70-
return false;
71-
}
72-
final TaskForm other = (TaskForm) obj;
73-
if (!Objects.equals(this.name, other.name)) {
74-
return false;
75-
}
76-
if (!Objects.equals(this.description, other.description)) {
77-
return false;
78-
}
79-
if (!Objects.equals(this.id, other.id)) {
80-
return false;
81-
}
82-
return true;
59+
public int hashCode() {
60+
return Objects.hash(id, name, description);
8361
}
8462

8563
@Override
8664
public String toString() {
87-
return "TaskForm{" + "id=" + id + ", name=" + name + ", description=" + description + '}';
65+
return "TaskForm{" +
66+
"id=" + id +
67+
", name='" + name + '\'' +
68+
", description='" + description + '\'' +
69+
'}';
8870
}
89-
9071
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.eclipse.krazo.engine;
2+
3+
import jakarta.annotation.Priority;
4+
import jakarta.enterprise.context.ApplicationScoped;
5+
import jakarta.mvc.engine.ViewEngine;
6+
import jakarta.mvc.engine.ViewEngineContext;
7+
import jakarta.mvc.engine.ViewEngineException;
8+
import jakarta.servlet.ServletException;
9+
import java.io.IOException;
10+
11+
/**
12+
* Implementation of the JSF Facelets engine. Uses a method in its base class to forward
13+
* a request back to the servlet container.
14+
*
15+
* @author Manfred Riem
16+
* @author Santiago Pericas-Geertsen
17+
* @see ViewEngineBase#resolveView(jakarta.mvc.engine.ViewEngineContext)
18+
*/
19+
@Priority(ViewEngine.PRIORITY_BUILTIN)
20+
@ApplicationScoped
21+
public class FaceletsViewEngine extends ServletViewEngine {
22+
23+
/**
24+
* Assumes that any view that ends with {@code .xhtml} is a facelet.
25+
*
26+
* @param view the name of the view.
27+
* @return {@code true} if supported or {@code false} if not.
28+
*/
29+
@Override
30+
public boolean supports(String view) {
31+
return view.endsWith(".xhtml");
32+
}
33+
34+
/**
35+
* Forwards request to servlet container.
36+
*
37+
* @param context view engine context.
38+
* @throws ViewEngineException if any error occurs.
39+
*/
40+
@Override
41+
public void processView(ViewEngineContext context) throws ViewEngineException {
42+
try {
43+
forwardRequest(context, "*.xhtml");
44+
} catch (ServletException | IOException e) {
45+
throw new ViewEngineException(e);
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)