Java Servlet 3.0 API 的 Maven 依赖?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1979957/
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
Maven dependency for Servlet 3.0 API?
提问by deamon
How can I tell Maven 2 to load the Servlet 3.0 API?
如何告诉 Maven 2 加载 Servlet 3.0 API?
I tried:
我试过:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
I use http://repository.jboss.com/maven2/but what repository would be correct?
我使用http://repository.jboss.com/maven2/但哪个存储库是正确的?
Addendum:
附录:
It works with a dependency for the entire Java EE 6 API and the following settings:
它依赖于整个 Java EE 6 API 和以下设置:
<repository>
<id>java.net</id>
<url>http://download.java.net/maven/2</url>
</repository>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
I'd prefer to only add the Servlet API as dependency, but "Brabster" may be right that separate dependencies have been replaced by Java EE 6 Profiles. Is there a source that confirms this assumption?
我更愿意仅将 Servlet API 添加为依赖项,但“Brabster”可能是正确的,因为 Java EE 6 Profiles 已替换了单独的依赖项。是否有消息来源证实了这一假设?
采纳答案by Pascal Thivent
I'd prefer to only add the Servlet API as dependency,
我宁愿只添加 Servlet API 作为依赖项,
To be honest, I'm not sure to understand why but never mind...
说实话,我不确定为什么但没关系......
Brabsterseparate dependencies have been replaced by Java EE 6 Profiles. Is there a source that confirms this assumption?
Brabster单独的依赖项已被 Java EE 6 Profiles 取代。是否有消息来源证实了这一假设?
The maven repository from Java.net indeed offers the following artifact for the WebProfile:
Java.net 的 maven 存储库确实为 WebProfile 提供了以下工件:
<repositories>
<repository>
<id>java.net2</id>
<name>Repository hosting the jee6 artifacts</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
This jar includes Servlet 3.0, EJB Lite 3.1, JPA 2.0, JSP 2.2, EL 1.2, JSTL 1.2, JSF 2.0, JTA 1.1, JSR-45, JSR-250.
这个 jar 包括 Servlet 3.0、EJB Lite 3.1、JPA 2.0、JSP 2.2、EL 1.2、JSTL 1.2、JSF 2.0、JTA 1.1、JSR-45、JSR-250。
But to my knowledge, nothing allows to say that these APIs won't be distributed separately (in java.net repository or somewhere else). For example (ok, it may a particular case), the JSF 2.0 API is available separately (in the java.net repository):
但据我所知,没有什么可以说这些 API 不会单独分发(在 java.net 存储库或其他地方)。例如(好吧,这可能是一种特殊情况),JSF 2.0 API 是单独可用的(在 java.net 存储库中):
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.0-b10</version>
<scope>provided</scope>
</dependency>
And actually, you could get javax.servlet-3.0.jar
from thereand install it in your own repository.
实际上,您可以javax.servlet-3.0.jar
从那里获取并将其安装在您自己的存储库中。
回答by brabster
I found an example POM for the Servlet 3.0 API on DZonefrom September.
我从 9 月开始在 DZone 上找到了Servlet 3.0 API的示例 POM 。
Suggest you use the java.net repo, at http://download.java.net/maven/2/
建议您使用 java.net 存储库,位于http://download.java.net/maven/2/
There are Java EE APIs in there, for example http://download.java.net/maven/2/javax/javaee-web-api/6.0/with POM that look like they might be what you're after, for example:
那里有 Java EE API,例如http://download.java.net/maven/2/javax/javaee-web-api/6.0/和 POM 看起来它们可能是你想要的,例如:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
</dependency>
I'm guessing that the version conventions for the APIs have been changed to match the version of the overall EE spec (i.e. Java EE 6 vs. Servlets 3.0) as part of the new 'profiles'. Looking in the JAR, looks like all the 3.0 servlet stuff is in there. Enjoy!
我猜测 API 的版本约定已更改为与整个 EE 规范的版本(即 Java EE 6 与 Servlets 3.0)相匹配,作为新“配置文件”的一部分。查看 JAR,看起来所有 3.0 servlet 的东西都在里面。享受!
回答by Ingo Fischer
Unfortunately, adding the javaee-(web)-api as a dependency doesn't give you the Javadoc or the Source to the Servlet Api to browse them from within the IDE. This is also the case for all other dependencies (JPA, EJB, ...) If you need the Servlet API sources/javadoc, you can add the following to your pom.xml (works at least for JBoss&Glassfish):
不幸的是,将 javaee-(web)-api 添加为依赖项不会为您提供 Javadoc 或 Servlet Api 的源以从 IDE 中浏览它们。对于所有其他依赖项(JPA、EJB 等)也是如此。如果您需要 Servlet API 源/javadoc,您可以将以下内容添加到您的 pom.xml(至少适用于 JBoss&Glassfish):
Repository:
存储库:
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
Dependency:
依赖:
<!-- Servlet 3.0 Api Specification -->
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
<version>1.0.0.Beta2</version>
<scope>provided</scope>
</dependency>
I completely removed the javaee-api from my dependencies and replaced it with the discrete parts (javax.ejb, javax.faces, ...) to get the sources and Javadocs for all parts of Java EE 6.
我从我的依赖项中完全删除了 javaee-api 并将其替换为离散部分(javax.ejb、javax.faces 等)以获取 Java EE 6 的所有部分的源代码和 Javadoc。
EDIT:
编辑:
Here is the equivalent Glassfish dependency (although both dependencies should work, no matter what appserver you use).
这是等效的 Glassfish 依赖项(尽管无论您使用什么应用程序服务器,这两个依赖项都应该有效)。
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.servlet</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
回答by Patrick Crocker
The Apache Geronimo project provides a Servlet 3.0 API dependency on the Maven Central repo:
Apache Geronimo 项目提供了对 Maven Central 存储库的 Servlet 3.0 API 依赖项:
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
</dependency>
回答by Andrey
A convenient way (JBoss recommended) to include Java EE 6 dependencies is demonstrated below. As a result dependencies are placed separately (not all in one jar as in javaee-web-api), source files and javadocs of the libraries are available to download from maven repository.
下面演示了一种包含 Java EE 6 依赖项的便捷方法(JBoss 推荐)。因此,依赖项是单独放置的(不像 javaee-web-api 那样全部放在一个 jar 中),库的源文件和 javadoc 可以从 maven 存储库下载。
<properties>
<jboss.javaee6.spec.version>2.0.0.Final</jboss.javaee6.spec.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-web-6.0</artifactId>
<version>${jboss.javaee6.spec.version}</version>
<scope>provided</scope>
<type>pom</type>
</dependency>
</dependencies>
To include individual dependencies only, dependencyManagement
section and scope import
can be used:
要仅包含单个依赖项,可以使用dependencyManagement
部分和范围import
:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee6-specs-bom</artifactId>
<version>${jboss.javaee6.spec.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- No need specifying version and scope. It is defaulted to version and scope from Bill of Materials (bom) imported pom. -->
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
</dependency>
</dependencies>
回答by cuh
Or you can use the Central Maven Repository with the Servlet 3.0 API which is also provided for the Tomcat Server 7.0.X
或者,您可以将中央 Maven 存储库与 Servlet 3.0 API 一起使用,该 API 也为 Tomcat Server 7.0.X 提供
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.21</version>
<scope>provided</scope>
</dependency>
from here: http://repo2.maven.org/maven2/org/apache/tomcat/tomcat-servlet-api/7.0.21/
从这里:http: //repo2.maven.org/maven2/org/apache/tomcat/tomcat-servlet-api/7.0.21/
回答by Sa'ad
This seems to be added recently:
这似乎是最近添加的:
http://repo1.maven.org/maven2/javax/servlet/javax.servlet-api/3.0.1/
http://repo1.maven.org/maven2/javax/servlet/javax.servlet-api/3.0.1/
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
回答by rustyx
Here is what I use. All of these are in the Central and have sources.
这是我使用的。这些都在中央,都有来源。
For Tomcat 7 (Java 7, Servlet 3.0)
对于 Tomcat 7(Java 7、Servlet 3.0)
Note - Servlet, JSP and EL APIs are provided in Tomcat. Only JSTL (if used) needs to be bundled with the web app.
注 - Tomcat 中提供了 Servlet、JSP 和 EL API。只有 JSTL(如果使用)需要与 Web 应用程序捆绑在一起。
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
For Tomcat 8 (Java 8, Servlet 3.1)
对于 Tomcat 8(Java 8、Servlet 3.1)
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
回答by Josh
Try this code...
试试这个代码...
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
</dependency>
回答by Sergii I.
Just for newcomers.
只为新人。
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>