I want use SDK Java EE 7, Glassfish 4 and Maven.
Is it correct? Please, draw attention to scopes.
1. For servlets:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
2. JSP without standart tags and without JSTL:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
</dependency>
3. For JSP with standard tags "c:"
<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 specification where this information contains?
There are a variety of options. As suggested in the question, one approach is to import the whole Java EE API. But you can also be more selective. You can instead just include the servlet API (this is for servlet API 3.0.1; more recent versions are available for the same artifact data, but older versions use the artifact id servlet-api
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 pulls in the relevant JSP dependencies; this isn't the case: if you need to use the JSP API at all, you do need a dependency for it (but it's worth noting that you don't necessarily need it, as discussed at this question). You should use the correct version of the JSP API that matches the Servlet API version you're using, so for servlet API 3.0.1 as I show above, you should use 2.2:
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
Like for the Servlet API, there have been changes in the dependency data for the JSP API; in this case for versions older than 2.0 the group id is just javax.servlet
, while for versions newer than 2.2 the artifact id has changed to javax.servlet.jsp-api
.
For JSTL, you should almost certainly just be using version 1.2. The new standard location for this version is:
<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, should any future updates be made to this library they will be included with this group/artifact ID, as this appears to be designed to fit appropriately with all the other most recent artifacts. Unlike the other artifacts, JSTL is not provided by the container, so the scope should not be set to "provided" as for the others.
You shouldn't be adding these dependencies to your project. Instantiations of the J2EE specification such as servlets should be provided by the application server's runtime.
In Eclipse, To add the Server Runtime for your application server. Right click the project and select Properties. Then Build Path > Add Library > Server Runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With