编译hadoop源码遇到问题 及时解决

在编译Hadoop源码时遇到BUILD FAILURE错误,原因是protoc版本过低。解决方案是升级到protoc2.4.1。详细步骤包括下载并解压protobuf,将protoc.exe复制到系统路径,使用maven package生成jar文件,通过protoc命令生成Java类。完成这些步骤后,编译问题得以解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


最近在研究hadoop,在用maven编译源码的过程中出现了个错误,一直编译过不去:


[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3:58.734s
[INFO] Finished at: Tue Jan 08 18:39:18 CST 2013
[INFO] Final Memory: 29M/71M
[INFO] ------------------------------------------------------------------------
[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]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :hadoop-common


各种查找之后,经过网上的大量查找之后发现原因:


原因:hadoop-1.0.1需要maven3.0+和protoc2.4+,以上错误是protoc版本过低导致的.

The Maven embedder provider with the system plugin ($IDEA_HOME/plugins/maven/lib) is named maven-embedder-1.1-SNAPSHOT.jar, which seems a rather bad version for a released project.
But the big issue for us is that is is bundling Maven 2.2.1.
When using the maven-enforcer-plugin in a project, and forcing Maven version to be  >= 3.0.2, the _generate sources_ action, which used the Maven embedder, fails saying: Detected Maven Version: 2.2.1 is not in the allowed range 3.0.2.
Unlike before, decent Maven embedders now exist (http://repo1.maven.org/maven2/org/apache/maven/maven-embedder/)
As we are using XMLBeans in some modules, that leads to compile issues.
Workaround: Use "external" Maven runner (lifecycle phases launch), but that is really annoying.
Could it be possible to update the embedder, or being able to choose to always use the external runner?


于是马上重新安装了protoc2.4(转)


第一部分:windows7 安装 protocol buffer  (如果没有安装Maven,先安装maven,并且maven -version 验证安装成功)

 

1. 下载地址: http://code.google.com/p/protobuf/downloads/list 。从这里下载protobuf-2.4.1.tar.gz 和 protoc-2.4.1-win32.zip 两个包。分别解压到各自目录。

2. 将protoc-2.4.1-win32中的protoc.exe拷贝到c:\windows\system32中。

3. 将proto.exe文件拷贝到解压后的XXX\protobuf-2.4.1\src目录中.

4. 进入XXX\protobuf-2.4.1\java 目录  执行maven package命令编辑该包 生成protobuf-java-2.4.1.jar文件(位于target目录中)。

5. 假设你的数据文件目录在XXX\data目录,把上一步生成的jar拷贝到该目录中即可。

6. 进入XXX\protobuf-2.4.1\examples目录,可以看到addressbook.proto文件,执行命令 protoc --java_out=. addressbook.proto 命令,如果生成com文件夹并在最终生成AddressBookProtos类则说明安装成功。

 

 

第二部分:使用篇

 

定义proto文件:

 

Java代码   收藏代码
  1. option java_outer_classname = "UserModelDatas";  
  2.   
  3. message ContextMatchedItemPair{  
  4.       
  5.     message Context{  
  6.         optional string time=1;  
  7.         optional int32 temperature=2;  
  8.         optional string weather=3;  
  9.         optional string location=4;  
  10.         optional int32 priority=5;  
  11.     }  
  12.     optional Context context=1;  
  13.     message MatchedItem{  
  14.   
  15.         optional string itemTypeId=1;  
  16.         optional double matchRatio=2;  
  17.         optional string approachType=3;  
  18.           
  19.         message Item{  
  20.             optional string itemID =1;  
  21.             optional string type=2;  
  22.             optional string url=3;  
  23.             optional string img=4;  
  24.             optional string title=5;  
  25.             optional string abs=6;  
  26.             optional string date=7;  
  27.             optional string sourceTypeId=8;  
  28.         }  
  29.           
  30.         optional Item item=4;  
  31.     }  
  32.     repeated MatchedItem matchedItem = 2;  
  33.       
  34. }  
  35. //out class  
  36. message UserModelData{  
  37.       
  38.     repeated ContextMatchedItemPair contextMatchedItemPair=1;  
  39. }  

 

 

执行命令:protoc --java_out=. UserModelData.proto  即在同级目录下生成UserModelDatas类,该类即可在工程中使用了。如果要使用的话,还需要在工程中引入安装过程中生成的protobuf-java-2.4.1.jar 。

 

PS: 注意到我的所有类型都是repeated或者optional,并没有用required。 个人习惯而已。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值