1

I created maven jar file from eclipse. Getting following error while running jar.

Error:

 A JNI error has occurred, please check your installation and try again

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataOutputStream
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source) 
    at java.lang.Class.privateGetMethodRecursive(Unknown Source)

Please guide whether any dependencies need to be added in pom.xml

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>utd.bigdata</groupId>
  <artifactId>hadoop1</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>hw1</name>
  <dependencies>
  <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-client</artifactId>
        <version>2.4.1</version>
  </dependency>
   <dependency>
     <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-common</artifactId>
      <version>2.7.3</version>
        <scope>compile</scope>
       </dependency>
  <!--  <dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-auth</artifactId>
    <version>2.4.1</version>
</dependency>-->
  </dependencies>
  <build>
    <plugins>
        <plugin>
            <!-- Build an executable JAR -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>bigdata.UploadHadoop</mainClass>
                        <classpathPrefix>classes/lib</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

Also is there any error in pom.xml?Please suggest any code changes

Community
  • 1
  • 1
Gokul S
  • 23
  • 6
  • Could you give some detail on how you are running the jar? Is it through Eclipse debug/runtime? Is it command line? What is the command line command? – ProgrammersBlock Feb 05 '17 at 03:56

3 Answers3

1

A regular .jar archive does not contain its dependencies at runtime, for this you can use the maven-assembly-plugin to create a fat executable Jar:

https://maven.apache.org/plugins/maven-assembly-plugin/usage.html

<!-- Create a fat Jar -->
<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <archive>
      <manifest>
        <mainClass>bigdata.UploadHadoop</mainClass>
      </manifest>
    </archive>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
  </configuration>
</plugin>
Luciano van der Veekens
  • 6,307
  • 4
  • 26
  • 30
0

As an alternative to a "fat jar", the hadoop jar runner also supports the "jar of jars" format. It's worth noting that it's not standard for a jar, but since it's supported in hadoop, here it is: How do I put all required JAR files in a library folder inside the final JAR file with Maven?

This format is a normal jar, but with a lib/ folder containing all dependency jars.

Community
  • 1
  • 1
jeff
  • 4,325
  • 16
  • 27
0

If you use maven-jar-plugin to build an executable jar, please read the document. http://maven.apache.org/shared/maven-archiver/examples/classpath.html#Make

First, add maven-jar-plugin in pom.xml

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        ...
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>bigdata.UploadHadoop</mainClass>
              <classpathPrefix>classes/lib</classpathPrefix>
            </manifest>
          </archive>
        </configuration>
        ...
      </plugin>
    </plugins>
  </build>

Second, It doesn't attach the dependency jars to the project jar. So you must be sure the dependency jars(hadoop-client, hadoop-common) are in classes/lib by yourself.

At last, I suggest that you use maven-shade-plugin to build an executable jar(fat jar) http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html It will attach the dependency jars to the result shade jar by itself. You also use maven-assembly-plugin to build an executable jar, but not recommended.

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>bigdata.UploadHadoop</mainClass>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
begginghard
  • 141
  • 1
  • 5
  • Hi, I have a very silly problem that I got stock into. I have a simple(just printing hello world) .class file locally which I can convert it to .jar and run it locally with no problem. However, when I put it in my hadoop cluster I face with a silly bug: JAR does not exist or is not a normal file: /usr/reihan/test.jar I also should mention that I can run hadoop-builtin-examples like wordcount with no problem but when I want to run my own jar I face with this problem. any idea? – Reihan_amn Sep 23 '17 at 00:10