Error: The package org.apache.commons is not accessible

半腔热情 提交于 2020-06-17 14:19:47

问题


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:

The package org.apache.commons is not accessible

For reference, I am trying to install the apache math commons library.


回答1:


Your code probably has two issues.

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.*;

or a specific class, e.g.

import org.apache.commons.math4.linear.FieldMatrix;

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.

Do one of the following:

  • 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 corresponding requires statement, e.g. by going to the line with the import statement and using the corresponding Quick Fix (Ctrl+1)


来源:https://stackoverflow.com/questions/62056713/error-the-package-org-apache-commons-is-not-accessible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!