【问题标题】:org.junit cannot be resolved Errors go on. however Adding jar filesorg.junit 无法解决 错误继续。但是添加jar文件
【发布时间】:2021-03-06 08:38:24
【问题描述】:

我添加了我的 jar 文件并编辑了我的 pom.xml 文件,但我仍然收到“无法解析导入 org.junit”错误。我已经从这里下载了 Java:https://www.selenium.dev/downloads/ 我打开了我的 jar 并添加到构建路径。出了什么问题?

这是我的 pom.xml 文件

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <release>15</release>
        </configuration>
      </plugin>
    </plugins>
  </build>
   <dependencies>
  <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-engine</artifactId>
    <version>5.5.2</version>
</dependency>

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.0</version>
</dependency>
<dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>21.0</version>
</dependency>
<dependency>
    <groupId>com.google.api-client</groupId>
    <artifactId>google-api-client</artifactId>
    <version>1.22.0</version>
</dependency>
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>23.0</version>
</dependency>
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.2</version>
</dependency>
   <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>6.8.1</version>
    <scope>test</scope>
</dependency>
 </dependencies>

【问题讨论】:

    标签: java eclipse selenium selenium-webdriver


    【解决方案1】:

    好的,看来您的 POM 文件中的 Junit 依赖项不完整。您只依赖于 Jupiter 引擎,而不依赖于 API。而且您已将其声明为完全依赖项,而不是测试范围的依赖项。

    我建议您查看 Maven 的 Junit 5 示例;嗯https://github.com/junit-team/junit5-samples/tree/r5.7.1/junit5-jupiter-starter-maven

    它展示了如何使用 Junit “BOM”依赖项,它将导入所有其他所需的 Junit 依赖项。像这样:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.junit</groupId>
                <artifactId>junit-bom</artifactId>
                <version>5.7.1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    

    【讨论】:

    • 向我们展示导致此编译错误的代码。并提供更多显示上下文的构建输出。并告诉我们您是如何构建...或运行测试的。
    【解决方案2】:
    Remove the external jars from the node "Modulepath".
    Select the node "Classpath" then add the external jars.
    Review that all the jars are under the node "Classpath".
    

    这解决了我的问题

    【讨论】:

    • OK ...所以你不需要做这种事情。使用 Eclipse 的 Maven 插件(正确),它会根据 POM 文件中关于依赖项的说明来设置类路径/构建路径。让我印象深刻的是,您需要花一些时间阅读 Maven 的工作原理以及 Maven / Eclipse 集成的工作原理。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 2011-09-04
    相关资源
    最近更新 更多