gpt4 book ai didi

java - 运行maven jar文件时出错

转载 作者:可可西里 更新时间:2023-11-01 15:27:24 26 4
gpt4 key购买 nike

我从 eclipse 创建了 maven jar 文件。运行 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 中是否有任何错误?请建议任何代码更改

最佳答案

常规 .jar 存档在运行时不包含其依赖项,为此您可以使用 maven-assembly-plugin 创建一个胖可执行 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>

关于java - 运行maven jar文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42047935/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com