gpt4 book ai didi

Java JUnit 无法解析import org

转载 作者:行者123 更新时间:2023-11-30 10:11:05 25 4
gpt4 key购买 nike

我在 arch linux 上使用 eclipse 2018-09 (4.9.0)openjdk10-src。但是我的 JUnit 导入不起作用。

它在添加类路径时说:

Source location: Not found

enter image description here

在类路径中添加 JUnit 后它仍然无法工作:

The import org cannot be resolved

enter image description here

最佳答案

您正在使用 module-info.java

你有三个选择:

  1. 如果您不需要模块系统的功能,只需删除 module-info.java
  2. 确保 junit jar 位于模块路径中,并且您在 module-info.java 中有匹配的 requires 语句
  3. 由于在 module-info.java 中具有测试依赖项是一个坏主意,您可以将 junit jar 留在类路径中,但创建一个单独的测试源文件夹(例如 src-tests 并使确保配置设置 Contains test sources;参见 https://www.eclipse.org/eclipse/news/4.8/jdt.php#JavaViewsAndDialogs ;它需要一个单独的输出文件夹,例如 bin-tests)并将您的测试移到那里。(Wenn 在命名模块中编译测试源,eclipse 隐式添加 --add-reads=ALL-UNNAMED,就像 maven 一样)

(还要确保检查您使用的是来自 junit 5 而不是来自 junit 4 的包名称。)

关于Java JUnit 无法解析import org,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52578931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com