Search code examples
javajarjstl

Why are there two JAR files for JSTL?


In order to use JSTL library, we need to download two jar files. For example javax.servlet.jsp.jstl-api-1.2.1.jar and javax.servlet.jsp.jstl-1.2.1.jar. I bet they have some interfaces and classes that allow us to use those tags. But whatever they have, why they didn't put it all inside a single jar file?


Solution

  • As Andreas pointed out:

    "One is the API, mostly interfaces, the other is the implementation. You need the API for compiling, you need both for running."


    The nub of your question is this:

    But whatever they have, why they didn't put it all inside a single jar file?

    The functionality of the classes in the javax.servlet.jsp.jstl-xxx.jar files are typically provided by your web container. You will find the classes in one of the web container's own JAR files. They may be different to the reference implementation version that you have found in Maven Central (or wherever).

    So, incorporating the classes in javax.servlet.jsp.jstl-1.2.1.jar into your WAR file in some way would either be redundant (because the classes are already provided), or it would be harmful because the reference implementation classes conflict with / don't work with other aspects of the web container implementation.

    At any rate, the fundamental reason for having separate JAR files is because separating the APIs and implementations is necessary for correct functioning and to reduce WAR file bloat. Of course, you are free to explicitly include both of the JARs in your webapp's WAR file anyway ....