11

I downloaded a copy of servlet-api.jar from java2s.com. How do I know what version it is? There's no reference on the site.

EDIT

Ah. Apologies. I should have listed the content of the wordpad output when I double clicked on the MANIFEST.MF file in the jar I got:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.)

As you can see it didnt tell me the version hence the question.

volvox
  • 3,014
  • 16
  • 51
  • 80
  • What do you want to do with this JAR file? It always scares me whenever one grabs a *separate* file which originally originated in a (large) implementation and in fact should/could not be used separately. – BalusC Oct 12 '10 at 11:38
  • I was using Tomcat 6 and am migrating to Glassfish 3. I searched the Glassfish heirarchy for the jar and it wasn't there. I've got other problems to fix first, but wondered whether I needed to pull in the jars which I was referencing in Tomcat when I migrated. – volvox Oct 12 '10 at 11:41
  • Why would you want to know this? Are you compiling using `javac` in command console or so? Well, in Glassfish the Servlet API is inside the `javaee.jar`. It's by the way good to know that you can use wildcards `*` in classpath since Java 1.6 so that you can just do `/path/to/appserver/lib/*` instead of defining each JAR separately. Also do not mix API implementations. Make sure that your `WEB-INF/lib` is *free* of servletcontainer-specific libraries. – BalusC Oct 12 '10 at 11:46
  • It makes now more sense why you would do like this. It's after all plain ignorance and stabbing around in the dark. I posted an answer in your [other question](http://stackoverflow.com/questions/3913444/tomcat-6-conversion-to-glassfish-v3-servlet-api-el-api-jars). Hopefully it turns on a light bulb in your head :) – BalusC Oct 12 '10 at 12:15
  • Thanks for your input, but referring to me being plain ignorant is rude. I call it learning. Specifically to this question, I'd never seen the sun-web.xml before having only dealt with Tomcat and as the autogenerated one referred to a servlets version in the `DOCTYPE` I just wanted to get it right. Please do not infer stuff from different questions. – volvox Oct 12 '10 at 14:16
  • Sorry if the wording has a different meaning to you. Nothing personal. As to your comment, this is IMO not learning. This is stabbing around in the dark. No one (decent) learning resource is telling you to do it like that (downloading the JAR file(s) separately and mixing different implementations). I suggest to go get some good book(s) which exposes the basic concepts of the Java, Java EE and Servlet API's. – BalusC Oct 12 '10 at 15:46
  • I didn't say I wasn't stabbing around in the dark. I was just defending the comment about ignorance. I'm posting here precisely because I was (obviously) stabbing around in the dark and needed a light. – volvox Oct 12 '10 at 16:42
  • @BalusC While I understand the guidance you offer, there is a plain simple need that led me to this page: I've got a bunch of `servlet-api.jar` files, and don't know which is which. One is in the Apache Tomcat 8 folder, another is in my [Vaadin](https://vaadin.com/home) project folder. I know Tomcat 8 supports Servlet API 3.1, but was curious what they are currently shipping. Likewise for Vaadin. Duplicating the .jar file, renaming `.jar` to `.zip`, unzipping to a folder, and reading the manifest file is a quick way to be sure what is what. – Basil Bourque Apr 14 '14 at 21:33

5 Answers5

13

use the below code snippet :

<%= session.getServletContext().getMajorVersion() %>.
<%= session.getServletContext().getMinorVersion() %>
Ravi.Kumar
  • 761
  • 2
  • 12
  • 34
11

you can get it from META-INF, you can explore the content of jar file using win rar or such archiving utils something like.

Name: javax/servlet/
Specification-Title: Java API for Servlets
Specification-Version: 2.4  

I personally prefer maven repo to download jar from.

jmj
  • 237,923
  • 42
  • 401
  • 438
7

you can extract the MANIFEST.MF from the META-INF directory of your jar file by using

jar xf servlet-api.jar META-INF/MANIFEST.MF

the manifest for version 2.4 that comes with tomcat looks like this for example

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.2
Created-By: 1.4.2_06-b03 (Sun Microsystems Inc.)

Name: javax/servlet/
Specification-Title: Java API for Servlets
Specification-Version: 2.4
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: javax.servlet
Implementation-Version: 2.4.public_draft
Implementation-Vendor: Apache Software Foundation
Nikolaus Gradwohl
  • 19,708
  • 3
  • 45
  • 61
  • Or in the shell: `$ unzip -q -c /opt/tomcat/apache-tomcat-6.0.32/lib/servlet-api.jar META-INF/MANIFEST.MF | grep '^Specification-Version'` =yields=> `Specification-Version: 2.5` (note (to OP): `servlet-api*.jar` usually isn't "downloaded" separately from the server itself; so one should "just know" that tomcat 6.0 implements servlet-api 2.5; the jar itself could be called anything (as is the case w/ glassfish)) – michael Mar 14 '13 at 04:18
  • (sorry, I just realized this was an ancient question; not sure why I found it as a recently asked question (tagged java). also, just so that I can add something actually constructive, this is kind of a duplicate of http://serverfault.com/questions/384172/keeping-application-library-versions-in-synch-with-server ) – michael Mar 14 '13 at 04:36
0

for followers, if it's in a jnlp distro, there may be an accompanying "version.xml" file that tells you what versions each jar is respectively.

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
0

It's basically inside your JAR's MANIFEST file under /META-INF/MANIFEST.MF:

Name: javax/servlet/
Specification-Title: Java API for Servlets
Specification-Version: 3.0
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: javax.servlet
Implementation-Version: 3.0.FR
Implementation-Vendor: Apache Software Foundation
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228