問題描述
“el‑api”在 pom.xml 中什麼時候有用? (When is "el‑api" useful in pom.xml?)
我在 pom.xml 中有這種情況:
<?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>com.jsf</groupId>
<artifactId>showcase</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>showcase</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>prime‑repo</id>
<name>Prime Repo</name>
<url>http://repository.primefaces.org</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld‑servlet‑shaded</artifactId>
<version>3.1.3.Final</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee‑web‑api</artifactId>
<version>8.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.faces</artifactId>
<version>2.3.14</version>
</dependency>
<dependency>
<groupId>jakarta.servlet.jsp.jstl</groupId>
<artifactId>jakarta.servlet.jsp.jstl‑api</artifactId>
<version>1.2.7</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven‑compiler‑plugin</artifactId>
<version>3.8.1</version>
<configuration>
<encoding>UTF‑8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven‑war‑plugin</artifactId>
<version>3.2.3</version>
<configuration>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
</plugin>
</plugins>
</build>
</project>
什麼時候出現:
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el‑api</artifactId>
<version>3.0.3</version>
<scope>provided</scope>
</dependency>
有用嗎? 我在我的 pom.xml 中嘗試了使用和不使用這種依賴關係,並且沒有什麼變化。就我而言,在這兩種情況下一切正常。有沒有這種依賴關係的缺失會產生錯誤的情況? .................... ......
參考解法
方法 1:
It's indeed already covered by javaee‑web‑api
. It's only useful during working in an IDE if the target server actually uses it, and it's in pom declared before the javaee‑web‑api
. When done so, then you will in the IDE:
- See javadocs from that API during code autocomplete
- See source code from that API during debug‑stepping into the API classes
</ul>
And even then it will be only useful if it actually contains improvements/fixes as compared to the ones in javaee‑web‑api
. But when it's declared after the javaee‑web‑api
in pom, then the ones in javaee‑web‑api
will be used instead, and you might see the wrong javadocs and/or source code as compared to the ones used by the target server while working in the IDE. In such case the child API (be it EL API, or Servlet API, or JSF API, or whatever else), will indeed become utterly useless in pom.
See also:
Unrelated to the concrete problem, the javaee‑web‑api
has been migrated to jakarta.jakartaee‑web‑api
. Update your pom accordingly.
(by Mario Palumbo、BalusC)