IntelliJ 添加的项目库在包中不起作用

IntelliJ added Project libraries doesn't work in packages

首先,我的问题和question1 and question2.

一模一样

但是question2只能找到解决方法。(有效,谢谢)但这并不能解决问题。

而问题1仅引用了IntelliJ网站上的说明,我完全按照这些说明进行了操作。但是问题依然存在。

问题是:

我在 Project Structure - Project Settings - Libraries.

中添加了两个罐子

它们在 Project Structure - Project Settings - Modules - [mymodule] - DependenciesProject - External Libraries 下拉列表。

但是,对于包内的 classes,库似乎是不可见的。但是对于直接在模块文件夹中创建的文件,库工作得很好。

(见下方截图)(BinaryOut 是 algs4.jar 中合法的 class)

此外,Invalidate Cache 也无济于事。

那么我应该如何配置库以便它们可以在包内工作?

这是您使用的库的问题:

Q. If I use a named package to structure my code, the compiler can no longer access the libraries in stdlib.jar. Why not?

A. The libraries in stdlib.jar are in the "default" package. In Java, you can't access classes in the default package from a named package. If you need to use our libraries with a named package, you can use the packaged version stdlib-package.jar.

Source