相关依赖
1.JDK 1.7+
2.maven 3.0+
3.findbugs
4.zlib headers 1.2.7+ (如果要编译得到native code)
5.cmake 2.6+
6.protocbuffer 2.5.0
7.windows SDK or Visual Studio 2010 SP1(如果是vs2010,最好升级为sp1,否则那个cvtres.exe会疯掉)
8.Cygwin
9.Hadoop源码
配置编译环境
- JDK
1.安装JDK
2.新建系统变量JAVA_HOME
=D:\Java\jdk
(JAVA_HOME路径不能有空格)
3.配置环境变量PATH,追加路径%JAVA_HOME%\bin
- maven
1.解压maven到D:\maven
2.新建系统变量M2_HOME
=D:\maven\
3.配置环境变量PATH,追加路径%M2_HOME%\bin
- Findbugs
1.解压Findbugs到D:\findbugs
2.配置环境变量PATH,追加路径D:\findbugs\bin
- zlib
1.解压zlib到D:\zlib
2.配置环境变量PATH,追加路径D:\zlib\
(路径一定要指向zlib.dll) - cmake
1.解压cmake到D:\cmake
2.配置环境变量PATH,追加路径D:\cmake\bin
- protobuffer
(我直接把protoc.exe放到C:\Windows\System32\
目录下,好像也可以)
1.解压protobuffer源码至D:\protobuf-2.5.0
2.解压protobuf-2.5.0-win64.zip中的protoc.exe复制到D:\protobuf-2.5.0\src
目录下
3.命令行进入源码目录,执行mvn install
4.配置环境变量PATH,追加路径指向protoc.exe - Cygwin
1.解压Cygwin到D:\Cygwin
2.配置环境变量PATH,追加路径D:\Cygwin\bin
- VS2010
编译Hadoop源码
- 设置环境变量Platform=x64 (Platform的大小写一定不能写错啊)
- 编译Hadoop
1.解压源码
2.使用VS2010编译源码
开始–>所有程序–>Microsoft Visual Studio 2010–>Visual Studio Tools–>Visual Studio x64 Win64 命令提示(2010)(我用这个有点问题,可以使用Visual Studio x64兼容命令提示)
在该命令行中进入hadoop源码目录,执行mvn package -Pdist,native-win -DskipTests -Dtar
,编译成功后的文件在hadoop-dist/target目录下
遇到的问题
1.hadoop-common编译失败
[INFO] --- hadoop-maven-plugins:2.6.0:version-info (version-info) @ hadoop-common ---
[WARNING] [svn, info] failed: java.io.IOException: Cannot run program "svn": CreateProcess error=2, ?????????
[WARNING] [git, branch] failed with error code 128
[INFO] SCM: NONE
......
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(55,5): error MSB8020: The build tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, please install Visual Studio 2010 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution".[C:\WorkSpace\hadoop-2.6.0-src\hadoop-common-project\hadoop-common\src\main\winutils\libwinutils.vcxproj]
已完成生成项目“C:\WorkSpace\hadoop-2.6.0-src\hadoop-common-project\hadoop-common\src\main\winutils\libwinutils.vcxproj
”(默认目标)的操作 - 失败。
已完成生成项目“C:\WorkSpace\hadoop-2.6.0-src\hadoop-common-project\hadoop-common\src\main\winutils\winutils.vcxproj.metaproj”(默认目标)的操作 - 失败。
已完成生成项目“C:\WorkSpace\hadoop-2.6.0-src\hadoop-common-project\hadoop-common\src\main\winutils\winutils.sln”(默认目标)的操作 - 失败。
生成失败。
......
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:exec (compile-ms-winutils) on project hadoop-common: Command execution failed. Process exited with an error: 1(Exit value: 1) -> [Help 1]
......
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :hadoop-common
解决方法,Visual Studio版本问题,官方默认使用Visual Studio 2010 Professional,但本文采用Visual Studio 2015,因此对于生成失败的项目,需要用Visual Studio 2015重新打开,升级项目至Visual Studio 2015版本即可:
C:\WorkSpace\hadoop-2.8.0-src\hadoop-common-project\hadoop-common\src\main\winutils\winutils.sln
2、 hadoop-hdfs编译失败
main:
[mkdir] Created dir: C:\WorkSpace\hadoop-2.6