Java 如何将 servlet api 添加到我的 pom.xml
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1370414/
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
how to add the servlet api to my pom.xml
提问by flybywire
How do I add the servlets API to my project's pom.xml
如何将 servlets API 添加到我的项目的 pom.xml
mvnrepository.com has lots of servlet api and similarly named projects, that I don't know which is the right one. Or are all of them ok?
mvnrepository.com 有很多 servlet api 和类似命名的项目,我不知道哪个是正确的。或者他们都没事?
采纳答案by digitaljoel
I believe most web/app servers come bundled with a version of the servlet api, so you won't want to bundle the api in your .war file. You will need to find out which version is included with your server, then you can use
我相信大多数 web/app 服务器都捆绑了 servlet api 的一个版本,所以你不会想在你的 .war 文件中捆绑 api。您需要找出您的服务器包含哪个版本,然后您可以使用
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api-version}</version>
<scope>provided</scope>
</dependency>
replacing servlet-api-version with your version. You will want to specify the "provided" scope so the api.jar isn't included in your war file.
用您的版本替换 servlet-api-version。您需要指定“提供的”范围,以便 api.jar 不包含在您的 war 文件中。
回答by Vineet Reynolds
It depends on which version of the servlet API you are using.
这取决于您使用的 servlet API 版本。
The javax.servletartifact will provide jars for all of the servlet API versions.
该的javax.servlet神器将所有的servlet API版本提供罐子。
回答by Michael Rutherfurd
We use
我们用
<dependency>
<groupId>javax</groupId>
<artifactId>j2ee</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
but if you only need the servlet api you might want to use
但如果你只需要 servlet api 你可能想要使用
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>?</version>
<scope>provided</scope>
</dependency>
回答by Rajkumar Singh
Scope provided can be used when you dont want to put jar file inside the WEB-INF/lib
folder instead you are supplying it at runtime either by container or JDK.
当您不想将 jar 文件放在WEB-INF/lib
文件夹中,而是在运行时通过容器或 JDK 提供它时,可以使用提供的范围。
回答by Neil
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
回答by amgohan
For servlet-api 3.1.0, here is the declaration :
对于 servlet-api 3.1.0,这里是声明:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>