无法使用maven dependancy执行jar文件

时间:2017-05-14 12:52:13

标签: java hadoop jar pom.xml

我正在尝试执行jar文件,但它显示如下错误:

java -jar HDFSTest1-1.0-SNAPSHOT.jar

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration
at hdfstest1.HDFSTestGUI1.<init>(HDFSTestGUI1.java:48)
at hdfstest1.HDFSTestGUI1$17.run(HDFSTestGUI1.java:561)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ClassNotFoundException: 
org.apache.hadoop.conf.Configuration
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.mycompany</groupId>
<artifactId>HDFSTest1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-core</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.jdesktop</groupId>
        <artifactId>beansbinding</artifactId>
        <version>1.2.1</version>
    </dependency>
</dependencies>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <mainClass>hdfstest1.HDFSTestGUI1</mainClass>
</properties>
<build>
    <plugins>
        <plugin>
            <!-- Build an executable JAR -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>hdfstest1.HDFSTestGUI1</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>hdfstest1.HDFSTestGUI1</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

的MANIFEST.MF:

Manifest-Version: 1.0
Built-By: dipsi
Class-Path: hadoop-core-1.2.1.jar commons-cli-1.2.jar xmlenc-0.52.jar 
jersey-core-1.8.jar jersey-json-1.8.jar jettison-1.1.jar stax-api-1.0
.1.jar jaxb-impl-2.2.3-1.jar jaxb-api-2.2.2.jar stax-api-1.0-2.jar ac
tivation-1.1.jar jackson-core-asl-1.7.1.jar jackson-jaxrs-1.7.1.jar j
ackson-xc-1.7.1.jar jersey-server-1.8.jar asm-3.1.jar commons-io-2.1.
jar commons-httpclient-3.0.1.jar junit-3.8.1.jar commons-logging-1.0.
3.jar commons-codec-1.4.jar commons-math-2.1.jar commons-configuratio
n-1.6.jar commons-collections-3.2.1.jar commons-lang-2.4.jar commons-
digester-1.8.jar commons-beanutils-1.7.0.jar commons-beanutils-core-1
.8.0.jar commons-net-1.4.1.jar jetty-6.1.26.jar servlet-api-2.5-20081
 211.jar jetty-util-6.1.26.jar jasper-runtime-5.5.12.jar jasper-compil
 er-5.5.12.jar jsp-api-2.1-6.1.14.jar servlet-api-2.5-6.1.14.jar jsp-2
 .1-6.1.14.jar ant-1.6.5.jar commons-el-1.0.jar jets3t-0.6.1.jar hsqld
 b-1.8.0.10.jar oro-2.0.8.jar core-3.1.1.jar jackson-mapper-asl-1.8.8.  

 jar beansbinding-1.2.1.jar
 Created-By: Apache Maven 3.0.5
 Build-Jdk: 1.8.0_121
 Main-Class: hdfstest1.HDFSTestGUI1

我已经尝试了互联网上几乎所有可用的解决方案,但我想我错过了一些我在这里无法理解的东西。有人可以帮助理解这个吗? 在此先感谢!!

我使用过hadoop-core.jar(1.2.1),其中包括mapreduce,hadoop-common等所有模块。我是否需要明确添加它?

1 个答案:

答案 0 :(得分:0)

不应该使用$HADOOP_HOME/bin/hadoop jar HDFSTest1-1.0-SNAPSHOT.jar命令来运行hadoop作业吗?

如果类路径中的所有罐子都没问题,那么除此之外我没有看到任何其他故障。