I'm learning how to make a servlet 3.1 compliant webapp, that will run on JBoss wildfly 10. I use maven for dependencies, and I'm unsure what the following dependencies do exactly, and if they are included/not included in the servlet container:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl.version}</version>
</dependency>
I already did some googling and would like verification or completion of the following information:
- The servlet api is provided by the servlet container, so I can add
<scope>provided</scope>
in Maven. However, why do I need to include this jar? Which classes or files will have errors when I remove it? - I'm not sure what javax.servlet.jsp-api does. My hello world example seems to run just fine if I don't include it. What does this do? And do I need to add
<scope>provided</scope>
or not? - The JSTL is not provided by any servlet container, so it must be explicitly added. This jar ensures that the
<c:xxx>
and other basic tags are processed correctly in my jsp's.
Marking a dependency as provided will make it available to the compile time and test classpaths but not to the runtime classpath - as you say the container will provide an implementation of these APIs at runtime.
If you are developing a web application it is unlikely you will be able to do without using classes from the Servlet API (HttpServletRequest, HttpServletResponse, Filter etc). While many frameworks abstract away much of the Servlet API it is still likely you will be required to work with these underlying API.
Yes, add scope provided. However you would only need this in the compile time classpath if, for example, you were creating a custom JSP tag by extending say, javax.servlet.jsp.tagext.TagSupport (although tag files provide a more modern way to create custom tags).
Yes and yes.