eclipse 线程“main”中的异常 java.lang.NoClassDefFoundError: com/google/common/base/Preconditions

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28317911/
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-09 05:29:09  来源:igfitidea点击:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Preconditions

eclipsehadoopmapreduce

提问by JGS

While running by java map reduce application in eclipse, and facing the below exception. I have included the commons-logging-1.2.jar file in my build path also, but still below is coming.

在eclipse中通过java map reduce应用程序运行时,遇到以下异常。我也在我的构建路径中包含了 commons-logging-1.2.jar 文件,但仍然在下面。

I am new to hadoop. Kindly help me out.

我是hadoop的新手。请帮帮我。

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Preconditions
    at org.apache.hadoop.conf.Configuration$DeprecationDelta.<init>(Configuration.java:314)
    at org.apache.hadoop.conf.Configuration$DeprecationDelta.<init>(Configuration.java:327)
    at org.apache.hadoop.conf.Configuration.<clinit>(Configuration.java:409)
    at AverageNosClass.main(AverageNosClass.java:71)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Preconditions
    at java.net.URLClassLoader.run(URLClassLoader.java:366)
    at java.net.URLClassLoader.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 4 more

采纳答案by kd0807

Make sure you have added the correct Jar to your build path..

确保您已将正确的 Jar 添加到您的构建路径中。

回答by Vinod S. Patil

Adding guava-11.0.2.jar to the build path solved the issue. This jar is in /share/hadoop/tools/lib folder. I have installed hadoop 2.4.0.

将 guava-11.0.2.jar 添加到构建路径解决了这个问题。这个 jar 位于 /share/hadoop/tools/lib 文件夹中。我已经安装了 hadoop 2.4.0。

回答by Yosser Abdellatif Goupil

this is caused by Guava-x.y.z.jar because it is missing make sure that you added it

这是由 Guava-xyzjar 引起的,因为它丢失了请确保您添加了它

回答by Sunil

My issue has been resolved by adding the following jar

我的问题已通过添加以下 jar 解决

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>13.0-rc1</version>
</dependency>

回答by Ajit K'sagar

Use google collection JAR from

使用谷歌收藏 JAR 来自

this might solve your problem.

这可能会解决您的问题。

回答by Edu Castrillon

I have had this error too when trying to use MRUnit and the maven dependency was not found, so I tried to add it manually. Is this your case?

我在尝试使用 MRUnit 时也遇到了这个错误并且没有找到 maven 依赖项,所以我尝试手动添加它。这是你的情况吗?

The problemis that if you add the jar manually, it will keep failing asking for the rest of MRUnit jars (the ones in the pom of MRUnit) until you add them all with the same version as in its pom.

问题是,如果你手动添加的罐子,它会继续失败,要求MRUnit罐的其余部分(在MRUnit的POM的那些),直到你使用相同版本的新增所有在其POM。

The causeof mrunit not being found was that I was not using the necessary classifier in the dependecy declaration

没有找到 mrunit的原因是我没有在依赖声明中使用必要的分类器

The solutionis adding the classifierhadoop1or hadoop2

溶液添加分类器hadoop1hadoop2

回答by sras

Is your Hadoop lib directory contains all the jar files which you used in your eclipse project ?

您的 Hadoop lib 目录是否包含您在 eclipse 项目中使用的所有 jar 文件?

If not place them in Hadoop lib directory and restart hadoop.

如果没有将它们放在 Hadoop lib 目录中并重新启动 hadoop。

回答by JavaTec

We had a similar issue, hoping this will help someone: We had the jar in our classpath, but still this issue occurred. The reason was - inside build.gradle it was being loaded as compileOnly. Changing it to implementationmade it work

我们有一个类似的问题,希望这对某人有所帮助:我们的类路径中有 jar,但仍然发生了这个问题。原因是 - 在 build.gradle 中,它被加载为compileOnly. 更改它以implementation使其工作

回答by Sanjeet Pandey

I have resolved this issue by adding the guava-14.0.1 library.

我已经通过添加 guava-14.0.1 库解决了这个问题。