zoukankan      html  css  js  c++  java
  • 编译hadoop源码遇到问题 及时解决


    最近在研究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。 个人习惯而已。



  • 相关阅读:
    数组中的逆序对 --剑指offer
    第一个只出现一次的字符 --剑指offer
    丑数 --剑指offer
    把数组排成最小的数 --剑指offer
    整数中1出现的次数 --剑指offer
    最小的k个数 --剑指offer
    数组中出现次数超过一半的数字 --剑指offer
    redis击穿,穿透,雪崩,分布式锁,api(jedis,luttuce)
    Java创建数据库新建表及初始化表
    generatorConfig.xml自动生成实体类,dao和xml
  • 原文地址:https://www.cnblogs.com/java20130722/p/3206999.html
Copyright © 2011-2022 走看看