Java:无法解析导入 org.apache.commons.lang [Eclipse]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27174990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:15:04  来源:igfitidea点击:

Java: The import org.apache.commons.lang cannot be resolved [Eclipse]

javaeclipse

提问by zack_falcon

I've been handed a java project for modification, so I went ahead and decided to set it up in my MacBook. I loaded the project into Eclipse (Luna), imported and added all the external jars necessary, and pretty much tried to copy the old setup.

我接到了一个要修改的 Java 项目,所以我继续并决定在我的 MacBook 中设置它。我将项目加载到 Eclipse (Luna) 中,导入并添加了所有必要的外部 jar,并且几乎尝试复制旧设置。

Then, I get this:
Marco

然后,我得到这个:
马可

Which is weird, because I could've sworn I added that as a JAR (same one from the old setup): PoloOh, wait. There it is.

这很奇怪,因为我可以发誓我将其添加为 JAR(与旧设置相同): 马球哦,等等。就是这样。

Now, according to this, which may or may not apply, as it is NetBeans(not sure if there's much of a difference), I should use org.apache.commons.lang3.StringEscapeUtils;

现在,根据这个,它可能适用也可能不适用,因为它是 NetBeans(不确定是否有很大区别),我应该使用org.apache.commons.lang3.StringEscapeUtils;

Which, however, gives me this:

然而,这给了我这个:

enter image description here

enter image description here

EDIT: Here's the part of the code that uses the StringEscapeUtils: enter image description here

编辑:这是使用 StringEscapeUtils 的代码部分: enter image description here

Sorry if this seems trivial, but I'm kinda stumped. Can anyone help? Thanks.

对不起,如果这看起来微不足道,但我有点难倒。任何人都可以帮忙吗?谢谢。

EDIT: It would appear that in trying to solve this problem, I ran into a different one. After changing the org.apache.commons.lang.StringEscapeUtils;into org.apache.commons.lang3.StringEscapeUtils;, I noticed the error also says Unable to load realm info from SCDynamic store.

编辑:似乎在尝试解决这个问题时,我遇到了另一个问题。更改org.apache.commons.lang.StringEscapeUtils;为后org.apache.commons.lang3.StringEscapeUtils;,我注意到错误也说Unable to load realm info from SCDynamic store

At this point, I'm not sure if I did solve the previous error, or not, as I probably need to fix this new error to proceed.

在这一点上,我不确定我是否确实解决了之前的错误,因为我可能需要修复这个新错误才能继续。

回答by Bhaskara

Fortunately or unfortunately your other libraries require an older version of your commons lang. That is, other libraries (like hadoop) may have a dependency on apache commons 2 library So include the older version commons-lang-2.x version library and it should work fine.

幸运或不幸的是,您的其他库需要旧版本的公共语言。也就是说,其他库(如 hadoop)可能依赖于 apache commons 2 库所以包括旧版本的 commons-lang-2.x 版本库,它应该可以正常工作。

Check this Apache Hadoop dependency link:

检查此 Apache Hadoop 依赖项链接:

http://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/dependency-analysis.html

http://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/dependency-analysis.html

There is a dependency on commons-lang version 2.6. So include that library in your eclipse classpath

依赖于 commons-lang 2.6 版。因此,将该库包含在您的 eclipse 类路径中