线程“main”java.lang.noclassdeffounderror中出现异常:org/apache/hadoop/util/tool

hfwmuf9z  于 2021-06-03  发布在  Hadoop
关注(0)|答案(3)|浏览(392)
I get below error when i package (jar) and run my defaulthadoopjob. 

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/util/Tool
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.util.Tool
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 12 more
Could not find the main class: DefaultHadoopJobDriver. Program will exit.

Commands used to build Jar. 

# jar -cvf dhj.jar

# hadoop -jar dhj.jar DefaultHadoopJobDriver

The above command gave me error "Failed to load Main-Class manifest attribute from dhj.jar"

rebuilt jar with manifest using below command

jar-cvfe dhj.jar defaulthadoopjobdriver。
hadoop-jar dhj.jarDefaultHadoopJobDriver——这返回了我上面报告的原始错误消息。
我的hadoop作业只有一个类“defaulthoopjobdrive”,它扩展了配置和实现工具,并将方法作为作业创建和inputpath、outpurpath集的唯一代码运行。我也在使用新的api。

I'm running hadoop 1.2.1 and the Job works fine from eclipse.

This might be something to do with the classpath. Please help.
rqqzpn5f

rqqzpn5f1#

你不必付出代价 hadoop -jar . 命令是这样的:

hadoop jar <jar> [mainClass] args...

如果这个jar再次得到 java.lang.ClassNotFoundException 例外情况下,您可以使用: hadoop classpath 命令查看是否 hadoop-core-1.2.1.jar 在hadoop安装类路径中存在吗?
仅供参考,如果它不在这个列表中,您必须将这个jar添加到hadoop lib目录中。

but5z9lq

but5z9lq2#

尝试用hadoop的lib文件夹中的所有hadoopjar构建hadoopjava代码。在本例中,您缺少hadoop core-*.jar中的hadoop util类
可以在jar中构建代码时指定类路径,也可以使用以下命令将其外部化

hadoop -cp <path_containing_hadoop_jars> -jar <jar_name>
tyky79it

tyky79it3#

如果有人在这里使用maven和lands:依赖性问题可以通过要求maven在父项目的jar中包含它所需要的任何jar来解决。这样,hadoop就不必在其他地方寻找依赖项——它自己就可以在那里找到依赖项。方法如下:1。转到pom.xml
将节添加到 <project> 标记,调用 <build> 将以下内容添加到 <build></build> 章节:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>1.7.1</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <artifactSet>
                        <excludes>
                            <exclude>org.slf4j:slf4j-api</exclude>
                            <exclude>junit:junit</exclude>
                            <exclude>jmock:jmock</exclude>
                            <exclude>xml-apis:xml-apis</exclude>
                            <exclude>org.testng:testng</exclude>
                            <exclude>org.mortbay.jetty:jetty</exclude>
                            <exclude>org.mortbay.jetty:jetty-util</exclude>
                            <exclude>org.mortbay.jetty:servlet-api-2.5</exclude>
                            <exclude>tomcat:jasper-runtime</exclude>
                            <exclude>tomcat:jasper-compiler</exclude>
                            <exclude>org.apache.hadoop:hadoop-core</exclude>
                            <exclude>org.apache.mahout:mahout-math</exclude>
                            <exclude>commons-logging:commons-logging</exclude>
                            <exclude>org.mortbay.jetty:jsp-api-2.1</exclude>
                            <exclude>org.mortbay.jetty:jsp-2.1</exclude>
                            <exclude>org.eclipse.jdt:core</exclude>
                            <exclude>ant:ant</exclude>
                            <exclude>org.apache.hadoop:avro</exclude>
                            <exclude>jline:jline</exclude>
                            <exclude>log4j:log4j</exclude>
                            <exclude>org.yaml:snakeyaml</exclude>
                            <exclude>javax.ws.rs:jsr311-api</exclude>
                            <exclude>org.slf4j:jcl-over-slf4j</exclude>
                            <exclude>javax.servlet:servlet-api</exclude>
                        </excludes>
                    </artifactSet>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/jruby.home</exclude>
                                <exclude>META-INF/license</exclude>
                                <exclude>META-INF/maven</exclude>
                                <exclude>META-INF/services</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
            </execution>
        </executions>
    </plugin>

现在再次构建您的项目,并以正常方式运行 hadoop java my.jar ... 命令。它现在不应该为依赖而哭泣。希望这有帮助!

相关问题