【问题标题】:Run map reduce job with 3rd party dependency in Jar在 Jar 中运行具有 3rd 方依赖项的 map reduce 作业
【发布时间】:2015-06-02 17:31:28
【问题描述】:

我正在尝试测试是否可以将 3rd 方依赖项 jar 放入我的 jar 中,将 jar SSH 到远程机器,然后运行 ​​map reduce 作业。

流程:

在我的项目中,我运行mvn clean package 并生成文件my-appy-1.0-SNAPSHOT.jaroriginal-my-appy-1.0-SNAPSHOT.jar。我将第一个文件 scp 到我的远程机器上并运行命令:

hadoop jar hadoop my-appy-1.0-SNAPSHOT.jar  /user/bli1/wordcount/input /user/bli1/wordcount/output

我也试过了:

hadoop my-appy-1.0-SNAPSHOT.jar WordCount /user/bli1/wordcount/input /user/bli1/wordcount/output

我不确定为什么会收到此错误:

Error: Could not find or load main class my-appy-1.0-SNAPSHOT.jar

pom.xml:

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.18.1</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.2</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <createDependencyReducedPom>false</createDependencyReducedPom>
              <artifactSet>
                <excludes>
                  <exclude>org.hamcrest:*</exclude>
                  <exclude>org.mockito:*</exclude>
                  <exclude>org.objenesis:*</exclude>
                </excludes>
              </artifactSet>
              <filters>
                <filter>
                  <artifact>*:*</artifact>
                  <excludes>
                    <exclude>META-INF/LICENSE</exclude>
                    <exclude>META-INF/license</exclude>
                    <exclude>META-INF/*.SF</exclude>
                    <exclude>META-INF/*.DSA</exclude>
                    <exclude>META-INF/*.RSA</exclude>
                  </excludes>
                </filter>
              </filters>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <manifestEntries>
                    <Main-Class>com.mycompany.app.WordCount</Main-Class>
                    <Build-Number>1</Build-Number>
                  </manifestEntries>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

【问题讨论】:

    标签: java maven jar mapreduce maven-shade-plugin


    【解决方案1】:

    打开您的 *.jar 文件并检查它的 MANIFEST.mf 文件。它应该包含带有“public static main()”方法的类的“Main-Class”行。如果没有“Main-Class”自己添加

    此链接将帮助您做到这一点:https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

    【讨论】:

    • 我正在使用阴影插件,我认为我需要做的就是在我的 pom.xml 中声明它:` com.mycompany.app.WordCount `。如果我错了,请纠正我
    【解决方案2】:

    您需要提供主类的完整路径,包括包名。

    hadoop my-appy-1.0-SNAPSHOT.jar com.mycompany.app.WordCount /user/bli1/wordcount/input /user/bli1/wordcount/output
    

    【讨论】:

      【解决方案3】:

      你通过jar文件运行的命令如下: hadoop jar jar_filename.jar package_name.class_name HDFS_inputfile_name HDFS_output_directory

      你的命令应该是

      hadoop jar my-appy-1.0-SNAPSHOT.jar com.mycompany.app.WordCount /user/bli1/wordcount/input /user/bli1/wordcount/output

      【讨论】:

        猜你喜欢
        • 2015-03-22
        • 2014-09-02
        • 2014-10-07
        • 1970-01-01
        • 2013-10-12
        • 1970-01-01
        • 1970-01-01
        • 2017-08-22
        • 2015-05-28
        相关资源
        最近更新 更多