包不存在错误 - 无法在目录中找到包[重复]

问题描述 投票:-2回答:1

这个问题在这里已有答案:

我有一个.java文件(由另一个dev构建),我从命令行运行以执行一些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个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.