MapReduceの使用alibaba.fastjsonにjava.lang.ClassNotFoundException:com.alibaba.fastjson.JSON

Hadoopのプログラムは、サードパーティの依存関係は、パッケージ化されたMapReduceプログラムはIDEAでのエラーを報告しているクラスタ上で実行、または糸に直接提出するfastjson紹介する:java.lang.ClassNotFoundExceptionが:com.alibaba.fastjson.JSON ...このエラー
によってmaven-組立・プラグインのカスタムパッケージング解決この問題
最初のアドオンプラグはpom.xmlファイルで宣言されました:

<ビルド>
        <プラグイン>
            <プラグイン>
                <のgroupId> org.apache.maven.plugins </のgroupId>
                <たartifactId> Mavenのアセンブリ・プラグイン</たartifactId>
                <構成>
                    <descriptorRefs>
                        <descriptorRef>ジャー付き依存性< / descriptorRef>
                    </ descriptorRefs>
                    <記述子>
                        <記述>のsrc /アセンブリ/ assembly.xml </記述>
                    </記述子>
                    <アーカイブ>
                        <マニフェスト>
                            <addClasspath>真</ addClasspath>
                            <mainClass> com.wxx.bigdata.mr.ETLApp </ mainClass>
                        </マニフェスト>
                    </アーカイブ>
                </構成>
                <実行>
                    <実行>
                        <ID>メイクアセンブリ</ ID>
                        <フェーズ>パッケージ</相>
                        <目標>
                            <目標>シングル</目標>
                        </目標>
                    </実行>
                </実行>
            </プラグイン>
        </プラグイン>
    </ビルド>
第二に、カスタムファイルassembly.xml
 

<アセンブリ
        のxmlns = "http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
        のxmlns:XSI = "http://www.w3.org/2001/XMLSchema-instance"
        XSI:のschemaLocation = "http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0
       http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <上記IDの上>カスタマー-依存関係</上記のid>
    <書式>
        <フォーマット> JAR </フォーマット>
    </フォーマット>
    <は! -それ以外の場合は、メインクラスを見つけることができません、ここではfalseに設定され、層のディレクトリを梱包含めるかどうかを指定します- >
    <includeBaseDirectory> falseに</ includeBaseDirectory>
    <ファイル集合>
        <ファイルセット>
            <ディレクトリ> $ {project.build。ディレクトリ} /クラス</ディレクトリ>
            <OUTPUTDIRECTORY> / </ OUTPUTDIRECTORY>
        </ファイルセット>
    </ファイルセット>
 
    <dependencySets>
        <dependencySet>
            <開梱>真</アンパック>
            <含んで>
                <include>のcom.alibaba:fastjson </ include>の
            </含ま>
        </ dependencySet>
    </ dependencySets>
< /アセンブリ>
项目的目录结构如图

次のような完全なpom.xmlファイル:

<?xmlのバージョン= "1.0"エンコード= "UTF-8">
<プロジェクトのxmlns = "http://maven.apache.org/POM/4.0.0"
         のxmlns:XSI = "のhttp://www.w3 .ORG / 2001 / XMLスキーマ・インスタンス」
         の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.wxx.bigdata </のgroupId>
    <たartifactId> Hadoopのプロジェクト</たartifactId>
    <バージョン> 1.0 </バージョン>
 
    <プロパティ>
        <project.build.sourceEncoding> UTF-8 </project.build.sourceEncoding>
        <maven.compiler.source> 1.8 </maven.compiler.source>
        <maven.compiler。ターゲット> 1.8 </maven.compiler.target>
        <hadoop.version> 2.6.0-cdh5.15.1 </hadoop.version>
        <zk.version> 3.4.5-cdh5.15.1 </zk.version>
        <curator.version> 4.0.0 </curator.version>
        <flume.version> 1.6.0-cdh5.15.1 </flume.version>
    </プロパティ>
 
    <リポジトリ>
        <リポジトリ>
            <ID> Clouderaの</ ID>
            <URL> https://repository.cloudera.com/artifactory/cloudera-repos </ URL>
        </リポジトリ>
    </リポジトリ>
 
    <依存性>
        <! - Hadoopの依赖- >
        <依存>
            <groupIdを> org.apache.hadoop </ groupIdを>
            <たartifactId> Hadoopのクライアント</たartifactId>
            <バージョン> $ {hadoop.version} </バージョン>
        </依存関係>
 
        <! - ZK依赖- >
        <依存性>
            <のgroupId> org.apache.zookeeper </のgroupId>
            <たartifactId>飼育係</たartifactId>
            <バージョン> $ {zk.version} </バージョン>
        </依存>
 
        <依存性>
            <のgroupId> org.apache。フリューム</のgroupId>
            <たartifactId>フリューム-NG-コア</たartifactId>
            <バージョン> $ {flume.version} </バージョン>
        </依存>
 
        <依存性>
            <のgroupId> com.alibaba </のgroupId>
            <たartifactId> fastjson </たartifactId>
            <バージョン> 1.2.51 </バージョン>
        </依存関係>
 
        <依存>
            <groupIdを> org.apache.commons </ groupIdを>
            <たartifactId>コモンズ-lang3 </たartifactId>
            <バージョン> 3.5 </バージョン>
        </依存>
 
        <依存性>
            <のgroupId> JUnitの</のgroupId>
            <たartifactId> JUnitの</たartifactId>
            <バージョン> 4.11 </バージョン>
            <スコープ>テスト</スコープ>
        </依存>
    </依存関係>
 
    <ビルド>
        <プラグイン>
            <プラグイン>
                <のgroupId> org.apache.maven.plugins </のgroupId>
                <たartifactId> Mavenのアセンブリ・プラグイン</たartifactId>
                <設定>
                    <descriptorRefs>
                        <descriptorRef>ジャーとの依存関係</ descriptorRef>
                    </ descriptorRefs>
                    <記述子>
                        <記述>のsrc /アセンブリ/ assembly.xml </記述>
                    </記述子>
                    <アーカイブ>
                        <マニフェスト>
                            <addClasspath>真</ addClasspath >
                            <mainClass> com.wxx.bigdata.mr.ETLApp </ mainClass>
                        </マニフェスト>
                    </アーカイブ>
                </構成>
                <実行>
                    <実行>
                        <ID>メイクアセンブリ</ ID>
                        <相>パッケージ</相>
                        <目標>
                            <目標>シングル</目標>
                        </目標>
                    </実行>
                </実行>
            </プラグイン>
        </プラグイン>
    < /ビルド>
</プロジェクト>
通过IDEA的にMaven打包、生成的自定义包

MVNクリーン真三個のjarパッケージ、第二の選択を生成= -Dmaven.test.skip、効果的なプロのテストを実行してインストールします

リリース5元の記事 ウォンの賞賛1 ビュー1244

おすすめ

転載: blog.csdn.net/huiminchi/article/details/103158359