2017-02-05 378 views
1

我從eclipse創建maven jar文件。在運行jar時出現跟蹤錯誤。運行maven jar文件時出錯

錯誤:

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) 

請指導任何相關性是否需要在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> 

也有在pom.xml中的任何錯誤?請建議任何代碼更改

+0

你可否詳細說明一下你如何運行jar?它是通過Eclipse調試/運行時?它是命令行嗎?什麼是命令行命令? – ProgrammersBlock

回答

1

常規.jar歸檔不包含其依賴關係a牛逼運行,爲此,你可以使用maven組件,插件創建脂肪可執行的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> 
0

如果您使用maven-jar-plugin構建可執行jar,請閱讀文檔。 http://maven.apache.org/shared/maven-archiver/examples/classpath.html#Make

首先,在pom.xml中添加的maven-JAR-插件

<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> 

其次,它不重視的依賴罐子到項目罐子。所以你必須確定依賴jar(hadoop-client,hadoop-common)在你自己的classes/lib中。

最後,我建議你用maven遮陽簾插件來構建一個可執行的JAR(脂肪JAR) http://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html 它將通過自身附加的依賴罐子結果樹蔭罐子。 你也使用maven-assembly-plugin來構建一個可執行的jar,但不推薦。

<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> 
+0

嗨,我有一個非常愚蠢的問題,我得到了股票。我有一個簡單的(只是打印hello world).class文件,我可以將它轉換爲.jar並在本地運行,沒有問題。然而,當我把它放在我的hadoop集羣中時,我遇到了一個愚蠢的錯誤:JAR不存在或者不是普通文件:/usr/reihan/test.jar我還應該提及我可以運行hadoop-builtin-例子wordcount沒有問題,但是當我想運行我自己的jar我面對這個問題。任何想法? –