eclipse导入/编译hadoop源代码

1. 确保安装好JDK和eclipse 

      详细教程见: http://blog.csdn.net/kangdakangdaa/article/details/11364985

2. 安装 Subclipse(Eclipse 的 SVN 插件)

      用于从 Hadoop 获得源代码。我们使用 eclipse 自带的软件安装功能,通过 Subclipse 提供的地址自动下载安装该插件。

  • 首先访问http://subclipse.tigris.org,在Download and Install页面找到与Eclipse版本合适的Subclipse版本,最新为1.6,将其Eclipse update site URL(即http://subclipse.tigris.org/update_1.6.x)复制下来;
  • 然后打开 eclipse 的菜单 Help > Install New Software,单击 Add 按钮,填入刚才复制的安装地址(即 http://subclipse.tigris.org/update_1.6.x),可将该地址取名为subclipse;点击OK回到 Install 窗口,选择 Subclipse,而后按 Next 逐步安装。
  • 此外,还需安装 SVN 所需的 JavaHL,执行如下命令行:
        $ sudo apt-get install libsvn-java

 

 但是实际上我发现在eclipse的选项中将SVN改成另外的一个库就可以了。。

Sudo apt-get install subversion subversion-tools


个人理解:

问题场景

一  .先将下载和编译源码的工具都装好:要注意版本

安装步骤:
1、安装Java和Eclipse(具体步骤略)
2、安装 Subclipse(Eclipse 的 SVN 插件)

      用于从 Hadoop 获得源代码。我们使用 eclipse 自带的软件安装功能,通过 Subclipse 提供的地址自动下载安装该插件。

  • 首先访问http://subclipse.tigris.org,在Download and Install页面找到与Eclipse版本合适的Subclipse版本,最新为1.6,将其Eclipse update site URL(即http://subclipse.tigris.org/update_1.6.x)复制下来;
  • 然后打开 eclipse 的菜单 Help > Install New Software,单击 Add 按钮,填入刚才复制的安装地址(即 http://subclipse.tigris.org/update_1.6.x),可将该地址取名为subclipse;点击OK回到 Install 窗口,选择 Subclipse,而后按 Next 逐步安装。
  • 此外,还需安装 SVN 所需的 JavaHL,执行如下命令行:
        $ sudo apt-get install libsvn-java 
  • 在eclipse.ini中加入  -Djava.library.path=/usr/lib/i386-linux-gnu/jni
3、输入命令sudo apt-get install ant安装ant
4、输入命令sudo apt-get install git-core安装git
5、sudo apt-get install maven2安装的maven版本过低,如果已安装,则输入命令
   sudo apt-get purge maven2 卸载。
   从apache网站下载maven3.0.4,到待安装的目录下(例如/opt)输入命令
   sudo tar xzf ~/Downloads/apache-maven-3.0.4-bin.tar.gz
   在/etc/profile中加上相关路径变量:
      export JAVA_HOME=/opt/jdk1.6.0_30
      export JRE_HOME=/opt/jdk1.6.0_30/jre
      export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
      export M2_HOME=/opt/apache-maven-3.0.4
      export M2=$M2_HOME/bin
      export PATH=$M2:$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
   输入mvn --version查看版本是否正确
6、输入命令sudo apt-get install g++安装编译环境,为下一步做准备
7、输入命令
   sudo apt-get purge libprotoc5 
   系统自带的protobuf卸载掉,因为版本过低
   从谷歌网站下载protobuf2.4.1压缩文件,到待安装的目录下(例如/opt)输入命令
   sudo tar -xzf ~/Downloads/protobuf-2.4.1.tar.gz
   进入protobuf目录,输入命令
   sudo ./configure --prefix=$INSTALL_DI
   sudo make
   sudo make check
   sudo make install
   输入protoc --version查看版本是否正确,如果找不到执行文件,则重启系统使设置生效


二 . 按照官网http://wiki.apache.org/hadoop/EclipseEnvironment指导,要把Hadoop下载到本地,并构建Eclipse开发环境,只需要三条指令:

$ git clone git://git.apache.org/hadoop-common.git
$ mvn install -DskipTests
$ mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true

在编译过程中遇到一些问题,在本文后面有相关解决办法。


 

两个插件都装好后就可以用maven工程导入hadoop源代码了。

打包命令:mvn install -Pdist -Dtar -DskipTests=true

生成:hadoop-dist/target/hadoop-0.24.0-SNAPSHOT.tar.gz


 

参考网址:

http://monton76.blog.163.com/blog/static/378380722012318882158/

http://wiki.apache.org/hadoop/EclipseEnvironment

http://stardust1900.blog.163.com/blog/static/141127703201182014421993

http://blog.csdn.net/basicthinker/article/details/6174442#comments

 


问题解决办法:

1. Eclipse并安装Subclipse1.6x插件后,使用svn过程中报如下错误:

Failed to load JavaHL Library.
These are the errors that were encountered:
no libsvnjavahl-1 in java.library.path
no svnjavahl-1 in java.library.path
/opt/local/lib/libsvnjavahl-1.0.0.0.dylib: no suitable image found. Did find: /opt/local/lib/libsvnjavahl-1.0.0.0.dylib: mach-o, but wrong architecture

原来是缺少一些关联文件,去subclipse的Wiki看了看,说需要安装libsvn-java,在Ubuntu 下安装很简单,命令如下:

sudo apt-get install libsvn-java

 

安装完后,这文件在/usr/lib/jni目录下,这个目录并不是eclipse的java.library.path路径之一,所以还需要修改eclipse.ini来告诉eclipse去哪找这个libsvn-java相关的文件.
打开eclipse.ini,在最后行加入如下内容(注意换行)

-Djava.library.path=/usr/lib/jni(如果是linux 32位系统,目录为/usr/lib/i386-linux-gnu/jni)
-Djava.library.path=/usr/share/java/

问题:Ubuntu Incompatible JavaHL library loaded.  1.7.x or later required

参考链接:http://www.linuxidc.com/Linux/2013-01/78714.htm
问题:eclipse-subclipse:unable to load default SVN Client
 卸载svn1.8.x版本,装1.6的版本

参考网址:http://wenku.baidu.com/view/306e6527482fb4daa58d4b3c.html


2. mvn 命令执行到HDFS失败
  从hadoop svn co出来代码后 mvn clean install -Dmaven.test.skip碰到的问题及解决
svn checkout http://svn.apache.org/repos/asf/hadoop/common/trunk/ hadoop-trunk

[INFO] Apache Hadoop HDFS ................................ FAILURE [0.234s]

关键错误信息:
[ERROR] Failed to execute goal on project hadoop-hdfs: Could not resolve dependencies for project org.apache.hadoop:hadoop-hdfs:jar:3.0.0-SNAPSHOT: Failure to findorg.apache.hadoop:hadoop-common:jar:tests:3.0.0-SNAPSHOT in https://repository.apache.org/content/repositories/snapshots was cached in the local repository, resolution will not be reattempted until the update interval of apache.snapshots.https has elapsed or updates are forced -> [Help 1]

解决办法:

错误提示无法解决依赖,通过google查到了HDFS-4041(down下来的trunk貌似也解决了这个bug),但是不顶用。所以直接到maven的本地repository(~/.m2/repository)下查看这个包是否存在。实际上肯定是不存在的,但是在编译hadoop-hdfs时,会在repository相应的目录下(~/.m2/repository/org/apache/hadoop/hadoop-common/3.0.0-SNAPSHOT)生成一个hadoop-common-3.0.0-SNAPSHOT-tests.jar.lastUpdated,看着和找不到的依赖很像。将后面的lastUpdated去掉变成jar包,HDFS就可以编译通过了。

 


5.org.apache.maven.plugin.MojoExecutionException: protoc failure

 

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (compile-proto) on project hadoop-common: An Ant BuildException has occured: exec returned: 127 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (compile-proto) on project hadoop-common: An Ant BuildException has occured: exec returned: 127
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    at... 
    Caused by: /Users/Shared/Workspace/hadoop/hadoop-common/hadoop-common-project/hadoop-common/target/antrun/build-main.xml:23: exec returned: 127

原因是缺少protocol buffer, 找不到protoc命令。

 


[ERROR]Failed to execute goal org.apache.hadoop:hadoop-maven-plugins:3.0.0-SNAPSHOT:protoc(compile-protoc) on project hadoop-c[Help1]org.apache.maven.lifecycle.LifecycleExecutionException:Failed to execute goal org.apache.hadoop:hadoop-maven-plugins:3.0.0-SNAPplugin.MojoExecutionException: protoc failure at

 

<code style="border-bottom:0px; border-left:0px; padding-bottom:0px; margin:0px; padding-left:0px; padding-right:0px; font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu Sans Mono','Bitstream Vera Sans Mono','Courier New',monospace,serif; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px"><span class="pln" style="border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">wget http</span><span class="pun" style="border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">:</span><span class="com" style="color:gray; border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">//protobuf.googlecode.com/files/protobuf-2.5.1.tar.gz</span><span class="pln" style="border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">
tar xzf protobuf</span><span class="pun" style="border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">-</span><span class="lit" style="color:#8000; border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">2.4</span><span class="pun" style="border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">.</span><span class="lit" style="color:#8000; border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">1.tar</span><span class="pun" style="border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">.</span><span class="pln" style="border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">gz
cd protobuf</span><span class="pun" style="border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">-</span><span class="lit" style="color:#8000; border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">2.4</span><span class="pun" style="border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">.</span><span class="lit" style="color:#8000; border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">1</span><span class="pln" style="border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">
</span><span class="pun" style="border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">./</span><span class="pln" style="border-bottom:0px; border-left:0px; padding-bottom:0px; background-color:transparent; margin:0px; padding-left:0px; padding-right:0px; vertical-align:baseline; border-top:0px; border-right:0px; padding-top:0px">configure
make
sudo make install
sudo ldconfig  (一定要执行)
</span></code><h3>导入Eclipse</h3><pre><code>mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
</code>
ldconfig几个需要注意的地方!

1. 往/lib和/usr/lib里面加东西,是不用修改/etc/ld.so.conf的,但是完了之后要调一下ldconfig,不然这个library会找不到

2. 想往上面两个目录以外加东西的时候,一定要修改/etc/ld.so.conf,然后再调用ldconfig,不然也会找不到

比 如安装了一个mysql到/usr/local/mysql,mysql有一大堆library在/usr/local/mysql/lib下面,这时就 需要在/etc/ld.so.conf下面加一行/usr/local/mysql/lib,保存过后ldconfig一下,新的library才能在程 序运行时被找到。

3. 如果想在这两个目录以外放lib,但是又不想在/etc/ld.so.conf中加东西(或者是没有权限加东西)。那也可以,就是export一个全局变 量LD_LIBRARY_PATH,然后运行程序的时候就会去这个目录中找library。一般来讲这只是一种临时的解决方案,在没有权限或临时需要的时 候使用。

4. ldconfig做的这些东西都与运行程序时有关,跟编译时一点关系都没有。编译的时候还是该加-L就得加,不要混淆了。

5. 总之,就是不管做了什么关于library的变动后,最好都ldconfig一下,不然会出现一些意想不到的结果。不会花太多的时间,但是会省很多的事\


git clone出现错误:fatal:could not create work dir 'hadoop-common'

要确保所有的操作都是在用户hadoop下完成的:

  1. ~$ sudo chown -R hadoop:hadoop /usr/local/hadoop 

 

posted @ 2014-07-11 16:30  晋心  阅读(863)  评论(0编辑  收藏  举报