Java 我怎么知道我有什么版本的 servlet-api.jar?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3913485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 06:46:18  来源:igfitidea点击:

How do I know what version of servlet-api.jar I have?

javaservletsjar

提问by volvox

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.

我从 java2s.com 下载了一份 servlet-api.jar。我怎么知道它是什么版本?网站上没有参考。

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:

啊。道歉。当我双击我得到的 jar 中的 MANIFEST.MF 文件时,我应该列出写字板输出的内容:

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.

正如你所看到的,它没有告诉我版本因此问题。

采纳答案by Jigar Joshi

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

您可以从 META-INF 获取它,您可以使用 win rar 或类似的归档工具来探索 jar 文件的内容。

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

I personally prefer maven repo to download jar from.

我个人更喜欢从 maven repo 下载 jar。

回答by Nikolaus Gradwohl

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

您可以使用以下命令从 jar 文件的 META-INF 目录中提取 MANIFEST.MF

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

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

例如,tomcat 附带的 2.4 版清单看起来像这样

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

回答by Buhake Sindi

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

它基本上在您的 JAR 的 MANIFEST 文件中/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

回答by Ravi.Kumar

use the below code snippet :

使用以下代码片段:

<%= session.getServletContext().getMajorVersion() %>.
<%= session.getServletContext().getMinorVersion() %>

回答by rogerdpack

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.

对于追随者,如果它在 jnlp 发行版中,可能会有一个随附的“version.xml”文件,告诉您每个 jar 分别是什么版本。