Java 如何配置 maven 以使用 servlet 3

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24855531/
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 15:13:51  来源:igfitidea点击:

How to config maven to use servlet 3

javamavenjakarta-eeservlet-3.0

提问by angus

I want to upgrade my webapp to use servlet 3.0 (insetd of 2.5). I am using WebLogic Server Version: 12.1.1.0 (12c),maven,java 7_10 and NetBeans 7.3.1

我想升级我的 webapp 以使用 servlet 3.0(插入 2.5)。我正在使用 WebLogic Server 版本:12.1.1.0 (12c)、maven、java 7_10 和 NetBeans 7.3.1

For some reason the only available servlet-api is 3.0-alpha-1 and not 3.0

出于某种原因,唯一可用的 servlet-api 是 3.0-alpha-1 而不是 3.0

<project xmlns="http://maven.apache.org/POM/4.0.0"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>3.0-alpha-1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.myfaces.core</groupId>
        <artifactId>myfaces-api</artifactId>
        <version>2.1.8</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.myfaces.core</groupId>
        <artifactId>myfaces-impl</artifactId>
        <version>2.1.8</version>
        <scope>compile</scope>
    </dependency>

采纳答案by Craig Otis

Your options are actually 3.0.1or 3.1.0of the final releases, and the artifact ID has been changed.Using the old servlet-apiartifact ID, the releases available are only 2.x, aside from the alpha you've found.

您的选项实际上是3.0.13.1.0最终版本,并且工件 ID 已更改。使用旧的servlet-api工件 ID,除了您找到的 alpha 之外,可用的版本只有 2.x。

If you update to javax.servlet-api, you'll find the newer 3.xreleases:

如果您更新到javax.servlet-api,您将找到较新的3.x版本:

http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api

http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api

You can update your POM to use:

您可以更新您的 POM 以使用:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
</dependency>

回答by g00dnatur3

Try this dependency

试试这个依赖

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
</dependency>

found here: http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api

在这里找到:http: //mvnrepository.com/artifact/javax.servlet/javax.servlet-api

There is also a version 3.0.1 if you need something closer to 3.0

如果您需要更接近 3.0 的版本,还有一个版本 3.0.1