Commit 2ce95d2b by Patryk Czarnik

Wprowadzenie profili Mavena i filtrowania

Dzięki temu można przygotowywać projekty na Jakarta 9 (WildFly 26)
i Jakarta 10 (WildFly 27-28). Wgrywanie raczej poza Eclipse.
parent 1d7d841a
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
<version>42.6.0</version> <version>[42.5, 43)</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<dependency> <dependency>
<groupId>jakarta.xml.bind</groupId> <groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId> <artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version> <!-- wersja przyjdzie z parenta, podobnie jak w Spring Boot -->
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -17,6 +17,82 @@ ...@@ -17,6 +17,82 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<profiles>
<profile>
<id>jakarta9</id>
<!-- Właściwe dla serwera WildFly 26 Preview -->
<activation><activeByDefault>true</activeByDefault></activation>
<properties>
<jstl.uri>http://java.sun.com/jsp/jstl/</jstl.uri>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>9.1.0</version>
</dependency>
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
<profile>
<id>jakarta10</id>
<!-- Właściwe dla serwera WildFly 27+ -->
<properties>
<jstl.uri>jakarta.tags.</jstl.uri>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId>
<version>10.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
</profiles>
<build> <build>
<pluginManagement> <pluginManagement>
<plugins> <plugins>
...@@ -37,9 +113,9 @@ ...@@ -37,9 +113,9 @@
</pluginManagement> </pluginManagement>
</build> </build>
<modules> <modules>
<module>rest_serwer</module>
<module>model</module> <module>model</module>
<module>baza</module> <module>baza</module>
<module>rest_serwer</module>
<module>rest_klient</module> <module>rest_klient</module>
<module>soap_api</module> <module>soap_api</module>
<module>soap_serwer</module> <module>soap_serwer</module>
......
To jest przykład "wielomodułowego projektu Maven".
Składa się on z wielu projektów-modułów, pomiędzy którymi mogą istnieć zależności.
W katalogu nadrzędnym zdefiniowany jest "parent project", który:
- jest typu pom
- sam nie zawiera żadnych źródeł
- sam nie powoduje powstawania żadnych artefaktów podczas budowania
- (teoretycznie istnieje możliwość zdefiniowania tu strony z dokumentacją src/site, ale tego nie robimy)
Plik pom w parencie:
- wymienia wszystkie moduły w elemencie <modules>
- ustala podstawowe kwestie, które są wspólne dla wszystkich modułów (np. wersja Javy)
- w elementach pluginManagement i dependencyManagement może wymienić wtyczki i biblioteki po to, aby ustalić ich wersje
! wpisanie czegość w pluginManagement lub dependencyManagement nie znaczy jeszcze, że dana rzecz będzie używana we wszystkich modułach; trzeba się do niej jawnie odwołać
Plik pom w module:
- wskazuje projekt nadrzędny w elemencie <parent>
- dziedziczy z niego m.in groupId i version, których raczej się nie zmienia (wszystkie moduły mają jednakowe)
- może mieć zależności do innych modułów tego samego projektu, przy czym:
* zabronione są zależności cykliczne
* odwołując się do modułów typu war (robimy to w ear) [generalnie, czegoś, co nie jest typu jar] trzeba dopisać <type>war</type>
* w <groupId> można wpisać ${project.groupId}, bo jest tkaie samo, jak nasze; analogicznie dla wersji
EAR
Specyfiką projektów "Enterprise Edition" jest format ear, który jest jeszcze poziom wyżej niż war: może zbierać wiele plików war i jar po to, aby wspólnie deployować je na serwer.
To dodatkowy moduł typu ear służy do budowania tego archiwum; wbrew intuicji nie robi się tego w parent.
Profile
Już po zajęciach wzbogacam ten projekt o profile Mavena i rozwiązuję w ten sposób niekompatybilność między WildFly 26 a późniejszymi wersjami.
W parent pom definiuję dwa profile "jakarta9" i "jakarta10". Domyślnym jest 9, a aby aktywować 10, należy uruchomić Mavena w wierszu poleceń
mvn -P jakarta10 clean package
lub w Eclipse / IntelliJ wskazać profil jakarta10 jako aktywny profil.
Najbardziej problematyczną rzeczą są identyfikatory uri dla taglibów w plikach JSP (w module sklep_web). Zamieniam je stosując kolejną Mavenową technikę: filtrowanie.
Plik war lub ear zbudowany zgodnie z profilem jakarta9 można wgrać na serwer WildFly 26 Preview (bo te "nie preview" obsługiwały jeszcze Java EE 8).
Plik war lub ear zbudowany zgodnie z profilem jakarta10 można wgrać na serwer WildFly 27 lub wyższy (gdy to piszę: 28).
Wgrywanie z poziomu Eclipse może nie działać.
...@@ -24,6 +24,12 @@ ...@@ -24,6 +24,12 @@
<artifactId>jakarta.json</artifactId> <artifactId>jakarta.json</artifactId>
<version>2.0.1</version> <version>2.0.1</version>
</dependency> </dependency>
<!-- inna implementacja: -->
<!-- <dependency>
<groupId>org.eclipse.parsson</groupId>
<artifactId>jakarta.json</artifactId>
<version>1.1.2</version>
</dependency> !-->
<dependency> <dependency>
<groupId>org.jboss.resteasy</groupId> <groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId> <artifactId>resteasy-client</artifactId>
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
<dependency> <dependency>
<groupId>jakarta.platform</groupId> <groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId> <artifactId>jakarta.jakartaee-web-api</artifactId>
<version>9.1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -19,17 +19,30 @@ ...@@ -19,17 +19,30 @@
<dependency> <dependency>
<groupId>jakarta.platform</groupId> <groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-web-api</artifactId> <artifactId>jakarta.jakartaee-web-api</artifactId>
<version>9.1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jstl</artifactId> <artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
<version>1.2</version> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>${project.artifactId}</finalName> <finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build> </build>
</project> </project>
\ No newline at end of file
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="c" uri="${jstl.uri}core"%>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
......
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="c" uri="${jstl.uri}core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%> <%@taglib prefix="sql" uri="${jstl.uri}sql"%>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
......
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="c" uri="${jstl.uri}core"%>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
......
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="c" uri="${jstl.uri}core"%>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
......
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="c" uri="${jstl.uri}core"%>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
......
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="c" uri="${jstl.uri}core"%>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
......
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="c" uri="${jstl.uri}core"%>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
...@@ -65,5 +65,7 @@ do ${param.max_price} ...@@ -65,5 +65,7 @@ do ${param.max_price}
<div class="action"><a href="edit_product">Dodaj nowy produkt</a></div> <div class="action"><a href="edit_product">Dodaj nowy produkt</a></div>
<p>Wersja JSTL: <code>${jstl.uri}</code></p>
</body> </body>
</html> </html>
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
<dependency> <dependency>
<groupId>jakarta.xml.ws</groupId> <groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId> <artifactId>jakarta.xml.ws-api</artifactId>
<version>4.0.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment