如何弄清楚为什么某些javax.servlet依赖项被添加到了Maven项目中 [英] How to figure out why certain javax.servlet dependency is added to a maven project

查看:402
本文介绍了如何弄清楚为什么某些javax.servlet依赖项被添加到了Maven项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Maven项目.在这里,我添加了以下依赖项

I have a Maven project. Here I have added the following dependency

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${javax.servlet.version}</version>
        <scope>provided</scope>
    </dependency>

{javax.servlet.version}的值为3.1.0

{javax.servlet.version} has the value 3.1.0

但是,当我在Eclipse中查看Maven依赖项时,看到添加了servlet-api-2.3.jar.因此,由于无法使用方法HttpServletRequest.getPart(),因此无法构建我的项目,该方法仅在启动Servlet 3.0时可用.

However when I look at the maven dependencies in Eclipse I see that servlet-api-2.3.jar is added. Due to this I am unable to build my project as I am unable to use the method HttpServletRequest.getPart(), which is available only starting Servlet 3.0.

是否仍要弄清楚为什么添加了2.3版?

Is there anyway of figuring out as to why the version 2.3 gets added ?

有什么办法可以避免这种情况?

Is there any way of avoiding this ?

推荐答案

从项目资源管理器中,可以右键单击pom.xml文件,然后选择

From the project explorer, you can right click the pom.xml file, and select

打开→ Maven POM编辑器

Open With → Maven POM Editor

然后选择Dependency Hierarchy选项卡.您所有明确声明的依赖项都将显示为顶级节点.您可以看到它们的所有传递依赖关系以及它们的传递依赖关系,等等.

Then select the Dependency Hierarchy tab. All of your explicitly declared dependencies will appear as top level nodes. You can see all of their transitive dependencies, and their transitive dependencies, and so on.

找到要排除的工件后,可以右键单击工件,然后选择Exclude Maven Artifact(然后选择将其从项目中排除).您可以通过选择pom.xml选项卡转到pom文件.您应该会看到

Once you find the one you want to exclude, you can right click the artifact, and select Exclude Maven Artifact (and select to exclude it from the project). You can go to your pom file by selecting the pom.xml tab. You should see some like

<exclusions>
    <exclusion>
        <artifactId>...</artifactId>
        <groupId>...</groupId>
    </exclusion>
</exclusions>

在依赖于此工件的依赖项中

In the dependency that depended on this artifact

这篇关于如何弄清楚为什么某些javax.servlet依赖项被添加到了Maven项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆