0

I'm pretty new on Cloudera Quick-start so sorry if my explanation will be not so clear. Anyway I'm writing a code in Java which read File from Hdfs. I build a Maven-Project and I set up all the dependencies in the pom.xml, but when I try to launch the jar from shell (java -jar jnameofthefile.jar) I'm getting this error: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInputStrea

This is my Java code:

package com.hdfs_java_api;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;



import java.io.InputStream;
import java.io.IOException;
import java.net.URI;

public class HadoopFileSystemCat {

public static void main(String [] args) throws IOException
{
    String uri = "hdfs://quickstart.cloudera:8020/user/hive/warehouse/Orders.csv";
    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(URI.create(uri), conf);
    InputStream in = null;

    try {

    in = fs.open(new Path(uri));


    IOUtils.copyBytes(in, System.out, 4096, false);
}finally{
    IOUtils.closeStream(in);
        }
}


}

And this is my pom.xml:

 <project xmlns="http://maven.apache.org/POM/4.0.0" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com</groupId>
<artifactId>cards</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>hdfs_java_api</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF- 
8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.apache.hadoop</groupId>
  <artifactId>hadoop-common</artifactId>
  <version>2.6.0-cdh5.13.0</version>
</dependency>

<dependency>
  <groupId>org.apache.hadoop</groupId>
  <artifactId>hadoop-yarn-common</artifactId>
  <version>2.6.0-cdh5.13.0</version>
</dependency>

<dependency>
  <groupId>org.apache.hadoop</groupId>
  <artifactId>hadoop-mapreduce-client-common</artifactId>
  <version>2.6.0-cdh5.13.0</version>
</dependency>

<dependency>
  <groupId>org.apache.hadoop</groupId>
  <artifactId>hadoop-mapreduce-client-core</artifactId>
  <version>2.6.0-cdh5.13.0</version>
</dependency>
</dependencies>

<repositories>
<repository>
  <id>cloudera</id>
  <name>cloudera</name>
  <url>https://repository.cloudera.com/artifactory/cloudera- 
   repos/</url>
</repository>
</repositories>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>

  <mainClass>com.hdfs_java_api.HadoopFileSystemCat</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

As i said I'm noob so be patient and try to be as much clear as possible, thank you in advance!

1 Answer 1

1

I think you are missing core library

<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-core</artifactId>
    <version>0.20.2</version>
</dependency>

After that make sure, you have included "Maven Dependencies" in build path.

enter image description here

And in Deployment Assembly -

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

I have added the core library but the same error come out
Is it properly downloaded ? Use maven>update project.
I did it, nothing change
First of all thx for your time, I included Maven dependencies but for the second step the Deployment Assembly was missing. So I added <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> to my .project file as explained here [stackoverflow.com/questions/8399885/… and it appeared but there was an error which said that this is not a virtual project, after some time Eclipse crashed. Maybe I need to reinstall eclipse also because it is photon version not EE.
I think you should follow other things also provided in this link by other users stackoverflow.com/questions/8399885/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.