错误:无法访问包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;
其次,您通过requires <module>;
语句. 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
文件(如果需要,可以通过右键单击项目文件夹并选择 Configure> Create module-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屋!