从命令行(eclipse外)运行Java Application(maven项目)时出错

时间:2015-07-07 16:52:08

标签: java eclipse maven hadoop

我需要从没有eclipse的机器上运行一个项目。所以不要做"运行Java应用程序"在eclipse中,我从命令行执行了以下操作:

mvn exec:java -Dexec.mainClass="org.myproject.myJob" -Dexec.args="/Users/edamame/part-r-00006 myOut"

然而,我收到以下错误,我在命令行中错过了什么?非常感谢你!

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java (default-cli) on project myProject: An exception occured while executing the Java class. org/apache/hadoop/mapreduce/Job: org.apache.hadoop.mapreduce.Job -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java (default-cli) on project myProject: An exception occured while executing the Java class. org/apache/hadoop/mapreduce/Job
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. org/apache/hadoop/mapreduce/Job
    at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:345)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 19 more
Caused by: java.lang.NoClassDefFoundError: org/apache/hadoop/mapreduce/Job
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3040)
    at java.lang.Class.getMethod0(Class.java:3010)
    at java.lang.Class.getMethod(Class.java:1776)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:281)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.mapreduce.Job
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

错误抱怨org.apache.hadoop.mapreduce.Job找不到,但我确实在我的pom.xml中有如下所示。我的pom.xml中有什么问题吗?

<dependencies>
    <dependency>
        <groupId>com.thoughtworks.xstream</groupId>
        <artifactId>xstream</artifactId>
        <version>1.4.4</version>
    </dependency>
    <dependency>
        <groupId>org.yaml</groupId>
        <artifactId>snakeyaml</artifactId>
        <version>1.14</version>
    </dependency>

    <dependency>
        <groupId>org.apache.pig</groupId>
        <artifactId>pig</artifactId>
        <version>0.12.1</version>
    </dependency>

    <dependency>
        <groupId>net.sourceforge.argparse4j</groupId>
        <artifactId>argparse4j</artifactId>
        <version>0.4.3</version>
    </dependency>
    <dependency>
        <groupId>com.google.collections</groupId>
        <artifactId>google-collections</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-core</artifactId>
        <version>1.0.3</version>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>commons-cli</groupId>
                <artifactId>commons-cli</artifactId>
            </exclusion>
            <exclusion>
                <groupId>xmlenc</groupId>
                <artifactId>xmlenc</artifactId>
            </exclusion>
            <exclusion>
                <groupId>commons-net</groupId>
                <artifactId>commons-net</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-util</artifactId>
            </exclusion>
            <exclusion>
                <groupId>tomcat</groupId>
                <artifactId>jasper-runtime</artifactId>
            </exclusion>
            <exclusion>
                <groupId>tomcat</groupId>
                <artifactId>jasper-compiler</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jsp-api-2.1</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jsp-2.1</artifactId>
            </exclusion>
            <exclusion>
                <groupId>commons-el</groupId>
                <artifactId>commons-el</artifactId>
            </exclusion>
            <exclusion>
                <groupId>net.java.dev.jets3t</groupId>
                <artifactId>jets3t</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>servlet-api-2.5</artifactId>
            </exclusion>
            <exclusion>
                <groupId>net.sf.kosmosfs</groupId>
                <artifactId>kfs</artifactId>
            </exclusion>
            <exclusion>
                <groupId>hsqldb</groupId>
                <artifactId>hsqldb</artifactId>
            </exclusion>
            <exclusion>
                <groupId>oro</groupId>
                <artifactId>oro</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.eclipse.jdt</groupId>
                <artifactId>core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>commons-cli</groupId>
        <artifactId>commons-cli</artifactId>
        <version>1.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>com.javadocmd</groupId>
        <artifactId>simplelatlng</artifactId>
        <version>1.3.0</version>
    </dependency>
</dependencies>

2 个答案:

答案 0 :(得分:1)

hadoop-core具有你的pom.xml中提供的范围,这意味着maven假设你将自己在classpath上以某种方式提供这个jar,你在这里没有做。因此,要么在运行命令时删除提供的标记,要么将jar添加到类路径中。

答案 1 :(得分:0)

您可以尝试删除.m2文件夹中的所有库,然后再次运行mvn clean和mvn install。