You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加Selenium的Maven依赖失败,pom.xml无法解析报错如何解决?

报错原因

该报错是pom.xml的标签层级结构错误导致的,<dependency>标签没有放在合法的父级节点范围内,或者上一个标签存在闭合问题。

解决步骤

  • 打开pom.xml定位到报错的第40行的<dependency>标签位置
  • 确认所有<dependency>标签都被包裹在全局<dependencies>标签对内部,正确的结构参考如下:
<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>
    <groupId>com.example</groupId>
    <artifactId>Website_Project</artifactId>
    <version>1.0-SNAPSHOT</version>

    <!-- 所有业务依赖必须放在dependencies标签内 -->
    <dependencies>
        <!-- 原有junit依赖 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
        <!-- 新增selenium依赖 -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.15.0</version>
        </dependency>
    </dependencies>
</project>
  • 检查上一个紧邻的标签是否存在闭合错误,比如漏写结束标签、注释格式错误、多余字符插入的情况
  • 确认没有把<dependency>误写入<build>、<plugins>、<dependencyManagement>等其他标签内部。如果是写在<dependencyManagement>中仅做版本声明,需要在外层<dependencies>中再次声明对应依赖才会实际引入
  • 修改完成后,在Eclipse中右键项目,选择Maven - Update Project刷新配置即可生效

内容的提问来源于stack exchange,提问作者SRD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 13:57:01