What maven needs are needed for Servlet, JSP and JSTL in Java EE 7?

I want to use the Java EE 7 SDK, Glassfish 4 and Maven SDK.
Is it correct? Please pay attention to the area.

1. For servlets:

<dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency> 

2. JSP without standard tags and without JSTL:

 <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> </dependency> 

3. For JSPs with standard c: tags

 <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> 

4. For JSP with JSTL

 <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> <scope>runtime</scope> </dependency> 

Do you know the specification that contains this information?

+4
source share
2 answers

You should not add these dependencies to your project. Instant J2EE specification actions, such as servlets, must be provided by the application server runtime.

In Eclipse, add server runtime for your application server. Right-click the project and select Properties. Then choose Build Path> Add Library> Server Runtime.

+5
source

There are many options. As suggested in this question, one approach is to import the entire Java EE API. But you can also be more selective. Instead, you can simply enable the servlet API (this is for the servlet API 3.0.1, later versions are available for the same artifact data, but older versions use the servlet-api artifact identifier instead):

  <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> 

The question implies that the JSTL package also attracts the corresponding JSP dependencies; this is not so: if you need to use the JSP API at all, you need a dependency for it (but it is worth noting that you do not need it, since it was discussed on this issue ). You must use the correct version of the JSP API that matches the version of Servlet API you are using , so for the servlet API 3.0.1, as shown above, you should use 2.2:

  <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> 

As for the Servlet API, changes were made to the dependency data for the JSP API; in this case, for versions older than 2.0, the group identifier is just javax.servlet , while for versions with versions above 2.2 the artifact identifier has changed to javax.servlet.jsp-api .

For JSTL, you are almost certainly using version 1.2. New default location for this version:

  <dependency> <groupId>javax.servlet.jsp.jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> 

although the old location, as shown in the question, continues to work correctly. Presumably, if any future updates are made to this library, they will be included in this group / artifact identifier, as this seems to be intended to match all the other latest artifacts. Unlike other artifacts, JSTL is not provided by the container, so the area should not be set as "provided" as for the rest.

+3
source

Source: https://habr.com/ru/post/1488287/


All Articles