我在 Eclipse Photon 中遇到了同样的问题。一旦我在 Eclipse Oxygen 中打开相同的项目,它就可以正常工作。我不知道这个问题的根本原因,但 Eclipse Oxygen 解决了这个问题。
也许是范围问题。例如,如果我想获得“REST Assured”的依赖项,Maven 存储库将为我提供以下示例:
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
如果我使用“测试”范围安装此依赖项,则依赖项的 .jar 文件将变暗,并且您无法导入它们,就像您所描述的那样:
因此,如果我想在运行时使用依赖项,您应该在范围标记上键入“compile”而不是“test”。会是这样的:
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.3.2</version>
<scope>compile</scope>
</dependency>
最后我得到了这样的东西:
因此,我建议您检查 .pom 文件中依赖项的范围。
希望有帮助。