一、linux下编译hadoop和eclipse-plugin
操作系统为 ubuntu10.0.4 x86
1.下载软件包
hadoop-1.0.4.tar.gz
eclipse-jee-indigo-SR2-linux-gtk.tar.gz
将二者解压到/software目录下,分别命名为eclipse3.7
即: HADOOP_HOME=/software/hadoop
2. 安装jdk
$ sudo apt-get install ant openjdk-6-jdk autoconflibtool
3.编辑{HADOOP_HOME}/build.xml
<property name="version"value="1.0.4-SNAPSHOT"/>
修改为:
<property name="version"value="1.0.4"/>
3.2
4.修改/hadoop-1.0.4/src/core/org/apache/hadoop/fs/FileUtil.java里面的checkReturnValue,注释掉该函数即可
(这一步非常重要,因为在windows下,使用hadoop-1.0.4自带的hadoop-core-1.0.4.jar时,会抛出权限异常:12/04/2415:32:44WARN util.NativeCodeLoader: Unable to load native-hadoop libraryfor your platform... using builtin-java classes whereapplicable,而修改了FileUtil.java后,编译得到的hadoop-core-1.0.4.jar在win平台不会出现上述问题)
- ......
-
private static void checkReturnValue(boolean rv, File p, -
FsPermission permission -
) throws IOException { -
-
} - ......
5.编辑{HADOOP_HOME}/src/contrib./build-contrib.xml
添加高亮的两行,补充Eclipse路径和Hadoop版本
<project name="hadoopbuildcontrib" xmlns:ivy="antlib:org.apache.ivy.ant">
...
</project>
6.编译
6.1 编译hadoop
$ cd /software/hadoop
$ ant compile
win平台下,使用编译生成的 hadoop-core-1.0.4.jar 可以避免
6.2编译eclipse-plugin
$ cd
$ ang jar
执行成功后, /software/hadoop/build/contrib./eclipse-plugin目录下会生成hadoop-eclipse-plugin-1.0.4.jar。
此时的hadoop-eclipse-plugin-1.0.4.jar还缺少一些jar包,放入${ECLIPSE_HOME}/plugins 后连接DFS会出现如下错误:
An internal error occurred during: "Connecting toDFSHadoop".org/apache/commons/configuration/Configuration
解决方法:
对hadoop-eclipse-plugin-1.0.4.jar进行修改。
5.1. 用归档管理器打开该包,发现只有commons-cli-1.2.jar 和hadoop-core.jar两个包。
将HADOOP_HOME/lib目录下的commons-configuration-1.6.jar ,commons-httpclient-3.0.1.jar , commons-lang-2.4.jar ,jackson-core-asl-1.8.8.jar 和jackson-mapper-asl-1.8.8.jar复制到hadoop-eclipse-plugin-1.0.3.jar的lib目录下
5.2. 修改该包META-INF目录下的MANIFEST.MF,将classpath修改为:
Bundle-ClassPath:classes/,lib/hadoop-core.jar,lib/commons-cli-1.2.jar,lib/commons-httpclient-3.0.1.jar,lib/jackson-core-asl-1.8.8.jar,lib/jackson-mapper-asl-1.8.8.jar,lib/commons-configuration-1.6.jar,lib/commons-lang-2.4.jar
将该hadoop-eclipse-plugin-1.0.4.jar拷贝到eclipse plugs-in目录中,重新启动eclipse,至此,搭建完成hadoop eclipse编译环境。
连接
二.Windows下编译eclipse-plugin
操作系统: win7 32
1.下载如下软件包:
jdk-6u30-windows-i586.exe
apache-ant-1.8.4-bin.zip
eclipse-jee-indigo-SR2-win32.zip
hadoop-1.0.4.tar.gz
2.
2.1安装jdk 配置JAVA_HOME,并将%JAVA_HOME%\bin添加到Path变量
2.2 将apache-ant-1.8.4-bin.zip解压到E:/software/目录下,配置ANT_HOME变量,
将%ANT_HOME%\bin添加到Path变量
2.3 将hadoop-1.0.4.tar.gz解压到E:/software/目录下
2.4将eclipse-jee-indigo-SR2-win32.zip解压到E:/software/目录下,更名为eclipse3.7
3.修改eclipse-plugin相关的build配置文件,并准备jar包
<project name="hadoopbuildcontrib" xmlns:ivy="antlib:org.apache.ivy.ant">
...
</project>
3.2
<path id="eclipse-sdk-jars"> |
(1)添加高亮的三行用于增加%Hadoop_HOME%/hadoop-*.jar作为ref
(2)删除build.xml中的deprecation=”${javac.deprecation}”
3.3 新建目录并复制jar包
>copy%Hadoop_HOME%\lib\commons-cli-1.2.jar%HADOOP_HOME%\build\ivy\lib\Hadoop\common\
>copy%Hadoop_HOME%\hadoop-core-1.0.4.jar %Hadoop_HOME%\build\
4. 命令行:切换到 %HADOOP_HOME%\src\contrib\eclipse-plugin目录下
此时的hadoop-eclipse-plugin-1.0.4.jar还缺少一些jar包,放入${ECLIPSE_HOME}/plugins 后连接DFS会出现如下错误:
An internal error occurred during: "Connecting toDFSHadoop".org/apache/commons/configuration/Configuration
解决方法:
对hadoop-eclipse-plugin-1.0.3.jar进行修改。
5.1. 用归档管理器打开该包,发现只有commons-cli-1.2.jar 和hadoop-core.jar两个包。
将HADOOP_HOME/lib目录下的commons-configuration-1.6.jar ,commons-httpclient-3.0.1.jar , commons-lang-2.4.jar ,jackson-core-asl-1.8.8.jar 和jackson-mapper-asl-1.8.8.jar复制到hadoop-eclipse-plugin-1.0.3.jar的lib目录下
5.2. 修改该包META-INF目录下的MANIFEST.MF,将classpath修改为:
Bundle-ClassPath:classes/,lib/hadoop-core.jar,lib/commons-cli-1.2.jar,lib/commons-httpclient-3.0.1.jar,lib/jackson-core-asl-1.8.8.jar,lib/jackson-mapper-asl-1.8.8.jar,lib/commons-configuration-1.6.jar,lib/commons-lang-2.4.jar
将该hadoop-eclipse-plugin-1.0.4.jar拷贝到eclipse plugs-in目录中,重新启动eclipse,至此,搭建完成hadoop eclipse编译环境。