错误:无法访问包 org.apache.commons [英] Error: The package org.apache.commons is not accessible
问题描述
我最近才开始使用 Eclipse,但在尝试安装外部库时遇到了问题.按照在线教程,我将 .jar
文件添加到类路径,并在引用的库文件夹中看到它.尽管如此,在尝试导入时,出现错误:
I have just recently started using Eclipse and am running into problems trying to install external libraries. Following online tutorials, I add the .jar
file to the classpath and I see it in the referenced libraries folder. Despite this, when trying to import, I get the error:
无法访问包 org.apache.commons
The package org.apache.commons is not accessible
作为参考,我正在尝试安装 apache math commons 库.
For reference, I am trying to install the apache math commons library.
推荐答案
你的代码可能有两个问题.
Your code probably has two issues.
首先,import 语句是错误的,因为在 Java 中你不能添加包本身,但包的所有类如下(注意 .*;
最后):
First, the import statement is wrong since in Java you cannot add a package itself, but all classes of a package as follows (note .*;
at the end):
import org.apache.commons.math4.linear.*;
或特定的类,例如
import org.apache.commons.math4.linear.FieldMatrix;
其次,您使用 Java 平台模块系统 (JPMS)>module-info.java 文件在默认包中可能没有必需的 requires
语句.JPMS 是在 Java 9 中引入的,你有 Java 12.
Second, you use the Java Platform Module System (JPMS) by having a module-info.java
file in the default package probably without the required requires <module>;
statement. JPMS was introduced in Java 9 and you have Java 12.
执行以下操作之一:
- 删除
module-info.java
文件(如果需要,您可以通过右键单击项目文件夹并选择配置>创建模块来重新创建它-info.java) - 在
module-info.java
添加对应的requires
语句,例如通过转到带有import
语句的行并使用相应的 Quick Fix (Ctrl+1)立>
- Delete the
module-info.java
file (if needed, you can recreate it via right-clicking the project folder and choosing Configure > Create module-info.java) - In
module-info.java
add the correspondingrequires
statement, e.g. by going to the line with theimport
statement and using the corresponding Quick Fix (Ctrl+1)
这篇关于错误:无法访问包 org.apache.commons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!