気まぐれな備忘録(仮)

いちようSEしてるので、プログラミングの備忘録的なものを書いてます

hadoop-0.20.2-cdh3u2をeclipseにインポートする

今、このエントリーを書いている時点で「CDH3u2」でぐぐると、
検索結果の1ページ目にこのブログがヒットして、
妙にテンションがあがっているkajitilunaです。

hadoop アドベントカレンダー 2011 1日目 CDH hadoop/hive/hbase を eclipse プロジェクトとしてインポートする」にて、
cdhのソースをeclipseにインポートする方法が紹介されていますが、
何気にこっそりmavenをたたいているので、
環境によっては失敗すると思います。

なので、mavenを叩かずに、
コンパイルエラー起こさずにインポートする方法をメモしておきます。
(というか、オイラの環境でナゼかmvnがエラー起こしていたので、その際のメモ)

とはいっても、やっていることは、
インポートした後にコンパイルエラーのディレクトリを
ぽちぽちexcludeしているだけダケドナー

さて、用意するものはコチラ

  • eclipse本体(アタリマエダ)
  • hadoop-0.20.2-cdh3u2.tar.gz(コレナクシテ、ナニヲいんぽーとスルツモリダ)
  • Lhaz(Lhaplusだと解凍時にエラー発生していたので、多分コレが無難)

hadoop-0.20.2-cdh3u2.tar.gz」のDL元は上記リンクを参照してください。

1.
上記ファイルを取得したら、さっそく解凍してください。
解凍後のディレクトリ「hadoop-0.20.2-cdh3u2」を好きなところに配置してください。

2.
このままeclipseにインポートしていいのですが、
そうするとGUIからぽちぽちexclude&ビルドの連続になって
時間がかかるので、必要なファイルを予め作成してから、インポートすることにします。

以下のファイル「.project」と「.classpath」を作成して、
上記の「hadoop-0.20.2-cdh3u2」ディレクトリ直下に配置してください。
なお、これらのファイルの内容はこちら。

「.project」

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
  <name>hadoop-0.20.2-cdh3u2</name>
  <comment></comment>
  <projects>
  </projects>
  <buildSpec>
    <buildCommand>
      <name>org.eclipse.jdt.core.javabuilder</name>
      <arguments>
      </arguments>
    </buildCommand>
  </buildSpec>
  <natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
  </natures>
</projectDescription>

「.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
  <classpathentry excluding="org/apache/hadoop/record/compiler/ant/" kind="src" path="src/core"/>
  <classpathentry kind="src" path="src/hdfs"/>
  <classpathentry kind="src" path="src/mapred"/>
  <classpathentry kind="src" path="src/contrib/capacity-scheduler/src/java"/>
  <classpathentry kind="src" path="src/contrib/data_join/src/examples"/>
  <classpathentry kind="src" path="src/contrib/data_join/src/java"/>
  <classpathentry excluding="org/apache/hadoop/eclipse/" kind="src" path="src/contrib/eclipse-plugin/src/java"/>
  <classpathentry kind="src" path="src/contrib/failmon/src/java"/>
  <classpathentry kind="src" path="src/contrib/fairscheduler/src/java"/>
  <classpathentry kind="src" path="src/contrib/gridmix/src/java"/>
  <classpathentry kind="src" path="src/contrib/hdfsproxy/src/java"/>
  <classpathentry kind="src" path="src/contrib/index/src/java"/>
  <classpathentry kind="src" path="src/contrib/mrunit/src/java"/>
  <classpathentry kind="src" path="src/contrib/streaming/src/java"/>
  <classpathentry kind="src" path="src/contrib/thriftfs/gen-java"/>
  <classpathentry kind="src" path="src/contrib/thriftfs/src/java"/>
  <classpathentry kind="src" path="src/contrib/vaidya/src/java"/>
  <classpathentry kind="src" path="src/examples"/>
  <classpathentry kind="src" path="src/tools"/>
  <classpathentry kind="lib" path="contrib/capacity-scheduler/hadoop-capacity-scheduler-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="contrib/capacity-scheduler/lib/jackson-core-asl-1.0.1.jar"/>
  <classpathentry kind="lib" path="contrib/capacity-scheduler/lib/jackson-mapper-asl-1.0.1.jar"/>
  <classpathentry kind="lib" path="contrib/datajoin/hadoop-datajoin-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="contrib/failmon/hadoop-failmon-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="contrib/fairscheduler/hadoop-fairscheduler-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="contrib/gridmix/hadoop-gridmix-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="contrib/gridmix/lib/jackson-core-asl-1.0.1.jar"/>
  <classpathentry kind="lib" path="contrib/gridmix/lib/jackson-mapper-asl-1.0.1.jar"/>
  <classpathentry kind="lib" path="contrib/hdfsproxy/hdfsproxy-2.0.jar"/>
  <classpathentry kind="lib" path="contrib/index/hadoop-index-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="contrib/index/lib/lucene-core-2.3.1.jar"/>
  <classpathentry kind="lib" path="contrib/mrunit/hadoop-mrunit-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="contrib/streaming/hadoop-streaming-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="contrib/streaming/lib/jackson-core-asl-1.0.1.jar"/>
  <classpathentry kind="lib" path="contrib/streaming/lib/jackson-mapper-asl-1.0.1.jar"/>
  <classpathentry kind="lib" path="contrib/thriftfs/hadoop-thriftfs-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="contrib/vaidya/hadoop-vaidya-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="hadoop-ant-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="hadoop-core-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="hadoop-examples-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="hadoop-test-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="hadoop-tools-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="ivy/ivy-2.0.0-rc2.jar"/>
  <classpathentry kind="lib" path="lib/ant-contrib-1.0b3.jar"/>
  <classpathentry kind="lib" path="lib/aspectjrt-1.6.5.jar"/>
  <classpathentry kind="lib" path="lib/aspectjtools-1.6.5.jar"/>
  <classpathentry kind="lib" path="lib/commons-cli-1.2.jar"/>
  <classpathentry kind="lib" path="lib/commons-codec-1.4.jar"/>
  <classpathentry kind="lib" path="lib/commons-daemon-1.0.1.jar"/>
  <classpathentry kind="lib" path="lib/commons-el-1.0.jar"/>
  <classpathentry kind="lib" path="lib/commons-httpclient-3.1.jar"/>
  <classpathentry kind="lib" path="lib/commons-logging-1.0.4.jar"/>
  <classpathentry kind="lib" path="lib/commons-logging-api-1.0.4.jar"/>
  <classpathentry kind="lib" path="lib/commons-net-1.4.1.jar"/>
  <classpathentry kind="lib" path="lib/core-3.1.1.jar"/>
  <classpathentry kind="lib" path="lib/hadoop-fairscheduler-0.20.2-cdh3u2.jar"/>
  <classpathentry kind="lib" path="lib/hsqldb-1.8.0.10.jar"/>
  <classpathentry kind="lib" path="lib/jackson-core-asl-1.5.2.jar"/>
  <classpathentry kind="lib" path="lib/jackson-mapper-asl-1.5.2.jar"/>
  <classpathentry kind="lib" path="lib/jasper-compiler-5.5.12.jar"/>
  <classpathentry kind="lib" path="lib/jasper-runtime-5.5.12.jar"/>
  <classpathentry kind="lib" path="lib/jets3t-0.6.1.jar"/>
  <classpathentry kind="lib" path="lib/jetty-6.1.26.cloudera.1.jar"/>
  <classpathentry kind="lib" path="lib/jetty-servlet-tester-6.1.26.cloudera.1.jar"/>
  <classpathentry kind="lib" path="lib/jetty-util-6.1.26.cloudera.1.jar"/>
  <classpathentry kind="lib" path="lib/jsch-0.1.42.jar"/>
  <classpathentry kind="lib" path="lib/jsp-2.1/jsp-2.1.jar"/>
  <classpathentry kind="lib" path="lib/jsp-2.1/jsp-api-2.1.jar"/>
  <classpathentry kind="lib" path="lib/junit-4.5.jar"/>
  <classpathentry kind="lib" path="lib/kfs-0.2.2.jar"/>
  <classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
  <classpathentry kind="lib" path="lib/mockito-all-1.8.2.jar"/>
  <classpathentry kind="lib" path="lib/oro-2.0.8.jar"/>
  <classpathentry kind="lib" path="lib/servlet-api-2.5-20081211.jar"/>
  <classpathentry kind="lib" path="lib/servlet-api-2.5-6.1.14.jar"/>
  <classpathentry kind="lib" path="lib/slf4j-api-1.4.3.jar"/>
  <classpathentry kind="lib" path="lib/slf4j-log4j12-1.4.3.jar"/>
  <classpathentry kind="lib" path="lib/xmlenc-0.52.jar"/>
  <classpathentry kind="lib" path="src/contrib/cloud/lib/pyAntTasks-1.3.jar"/>
  <classpathentry kind="lib" path="src/contrib/thriftfs/lib/hadoopthriftapi.jar"/>
  <classpathentry kind="lib" path="src/contrib/thriftfs/lib/libthrift.jar"/>
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  <classpathentry kind="output" path="target/classes"/>
</classpath>

上記の設定は、classファイルを「target/classes」に出力する設定になっている。
嫌なら、「kind="output"」に設定するpathの値を修正すること。


そいや、書いてから気付いたけど、
Windowsだと画面から「.project」や「.classpath」、「.txt」のような、
ファイル拡張子の前に何もないファイルは作成できないのだった。。

でも、こうすれば上記のようなファイルも作成できる。

  1. どこでもいいので、右クリックから「新規作成 > テキストファイル」を選択する。
  2. ファイル名は何でもよい。ここでは例として「aaa.txt」とする。
  3. コマンドプロンプトを開き、「aaa.txt」を作成したディレクトリに移動する。
  4. 「.project」というファイル名を作る場合「move aaa.txt .project」を実行する。

こうすれば、「aaa.txt」のファイル名が「.project」に変わるので、
後はテキストエディタで編集すればよい。


3.
上記のファイルの準備が完了すれば、eclipseにインポートする。
eclipseを起動したら、メニューから「File > Import」を選択する。
Importダイアログでは、
「General > Existing Projects into Workspace」を選択して「Next」を押下。

次のダイアログでは、
「Select root directory」で「hadoop-0.20.2-cdh3u2」を指定し、
Projectsにディレクトリと同一名のProjectが表示されたのを確認したら「Finish」を押下。

インポート後、ビルドが完了すると、
コンパイルエラーなしでインポートが完了している、、、はず

ちなみに、今回の設定では、testコードは基本的にビルドパスから外しています。
testコードも合わせて見たい!という人は、、、このエントリーは無視して、mavenたたきな


4.
その他、hbaseやhive、flumeもほぼ同様のことをすればインポートできます。
が、ここに載せるのが面倒くさくなったので、後日、気が向いたときにでも。

mvnを動かさない場合のインポートで注意することは、、
hbase → 特になし。hadoopと同じ流れでできる
flume → hbaseのjarをもってくる必要がある。影響するのは、hbasepluginのところ
hive → 意外とメンドイ。Servlet-APIが必要なはず。


ひとまずこんなカンジで。もう寝ます。