【问题标题】:package does not exist error - cannot find packages within directory [duplicate]包不存在错误-在目录中找不到包[重复]
【发布时间】:2018-02-27 15:40:25
【问题描述】:

我有一个 .java 文件(由另一个开发人员构建),我从命令行运行它来执行一些 Selenium 测试。

SeleniumsTests.java
/lib (directory of dependencies)

当我尝试直接从终端运行这个 java 文件时,它会返回一系列与无法找到保存在 lib 目录中的包相关的错误。

SeleniumsTestsjava:21: error: package org.junit does not exist
import org.junit.Assert;
            ^
SeleniumsTests.java:22: error: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
                      ^
SeleniumsTests.java:23: error: package org.openqa.selenium does not exist
import org.openqa.selenium.Keys;
                      ^
SeleniumsTests.java:24: error: package org.openqa.selenium does not exist
import org.openqa.selenium.WebDriver;

// other similar related errors

在 .java 本身中,我可以在以下导入中看到这些包的链接,但我看不到它如何链接到相应的文件夹“lib”——我该怎么做才能在这个 lib 目录中反映这些包

import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;

【问题讨论】:

  • 你需要添加带有类路径的库

标签: java selenium import


【解决方案1】:

对于每个 java 程序,如果它依赖于外部 jar 文件,您必须将它们添加到 java 类路径中。首先用谷歌搜索外部 jar,例如 download jar org.openqa.selenium and org.junit,然后从 maven 站点下载它们并将它们添加到您的 java 类路径并使用 javac 编译并像 java -classpath "class-path" javaclassfileNamewithoutextension 一样运行(不带 .class 的扩展名):-

【讨论】:

    猜你喜欢
    • 2021-10-23
    • 2020-11-10
    • 1970-01-01
    • 2013-07-13
    • 2013-12-09
    • 1970-01-01
    • 2014-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多