From zero teaches you how to get hadoop2.4 source code and use Eclipse to associate hadoop2.4 source code
Http://www.aboutyun.com/thread-8211-1-1.html
(Source: About Cloud development)
Problem Guide:
1. How to get all the code for Hadoop via the official website src package
3.maven?
If we want to develop, researching the source code is very helpful to us. Do not understand the principle is like a black box, encounter problems, we can not touch the idea. So here you are.
I. How to obtain the source code
two. How to associate source code
How to get the source code
1. Download the maven package for Hadoop
(1) Download the website
Here we first download maven package hadoop-2.4.0-src.tar.gz from the official website.
Official website
For those who do not know how to download the official website, you can view: Beginner's Guide: Introduction to Hadoop website and how to download Hadoop (2.4) Versions and view Hadoop API introduction
(2) screen download
can also be downloaded from the network disk:
Http://pan.baidu.com/s/1kToPuGB
2. There are two ways to get the source code through MAVEN
, one way through the command line, and one through eclipse. This is mainly about the way of the command
Get the source code by command:
1. Unpacking the package
The following problem was encountered while unpacking the package. But don't worry, let's go down
1: Unable to create file: D:\hadoop2\hadoop-2.4.0-src\hadoop-yarn-project\hadoop-yarn\hadoop-yarn-server\ Hadoop-yarn-server-applicationhistoryservice\target\classes\org\apache\hadoop\yarn\server\ Applicationhistoryservice\applicationhistoryclientservice$applicationhsclientprotocolhandler.class:
The total length of the path and filename cannot exceed 260 characters
The system could not find the path specified. D:\hadoop2\hadoop-2.4.0-src.zip
2: Unable to create file: D:\hadoop2\hadoop-2.4.0-src\hadoop-yarn-project\hadoop-yarn\hadoop-yarn-server\ Hadoop-yarn-server-applicationhistoryservice\target\classes\org\apache\hadoop\yarn\server\ Applicationhistoryservice\timeline\leveldbtimelinestore$lockmap$countingreentrantlock.class: The system cannot find the path specified. D:\hadoop2\hadoop-2.4.0-src.zip
3: Unable to create file: D:\hadoop2\hadoop-2.4.0-src\hadoop-yarn-project\hadoop-yarn\hadoop-yarn-server\ Hadoop-yarn-server-applicationhistoryservice\target\test-classes\org\apache\hadoop\yarn\server\ Applicationhistoryservice\webapp\testahswebapp$mockapplicationhistorymanagerimpl.class: The system cannot find the path specified. D:\hadoop2\hadoop-2.4.0-src.zip
4: Unable to create file: D:\hadoop2\hadoop-2.4.0-src\hadoop-yarn-project\hadoop-yarn\hadoop-yarn-server\ Hadoop-yarn-server-resourcemanager\target\test-classes\org\apache\hadoop\yarn\server\resourcemanager\monitor\ Capacity\testproportionalcapacitypreemptionpolicy$ispreemptionrequestfor.class:
The total length of the path and filename cannot exceed 260 characters
The system could not find the path specified. D:\hadoop2\hadoop-2.4.0-src.zip
5: Unable to create file: D:\hadoop2\hadoop-2.4.0-src\hadoop-yarn-project\hadoop-yarn\hadoop-yarn-server\ Hadoop-yarn-server-resourcemanager\target\test-classes\org\apache\hadoop\yarn\server\resourcemanager\recovery\ Testfsrmstatestore$testfsrmstatestoretester$testfilesystemrmstore.class: The system cannot find the path specified. D:\hadoop2\hadoop-2.4.0-src.zip
6: Unable to create file: D:\hadoop2\hadoop-2.4.0-src\hadoop-yarn-project\hadoop-yarn\hadoop-yarn-server\ Hadoop-yarn-server-resourcemanager\target\test-classes\org\apache\hadoop\yarn\server\resourcemanager\recovery\ Testzkrmstatestore$testzkrmstatestoretester$testzkrmstatestoreinternal.class:
The total length of the path and filename cannot exceed 260 characters
The system could not find the path specified. D:\hadoop2\hadoop-2.4.0-src.zip
7: Unable to create file: D:\hadoop2\hadoop-2.4.0-src\hadoop-yarn-project\hadoop-yarn\hadoop-yarn-server\ Hadoop-yarn-server-resourcemanager\target\test-classes\org\apache\hadoop\yarn\server\resourcemanager\recovery\ Testzkrmstatestorezkclientconnections$testzkclient$testforwardingwatcher.class:
The total length of the path and filename cannot exceed 260 characters
The system could not find the path specified. D:\hadoop2\hadoop-2.4.0-src.zip
8: Unable to create file: D:\hadoop2\hadoop-2.4.0-src\hadoop-yarn-project\hadoop-yarn\hadoop-yarn-server\ Hadoop-yarn-server-resourcemanager\target\test-classes\org\apache\hadoop\yarn\server\resourcemanager\recovery\ Testzkrmstatestorezkclientconnections$testzkclient$testzkrmstatestore.class:
The total length of the path and filename cannot exceed 260 characters
The system could not find the path specified. D:\hadoop2\hadoop-2.4.0-src.zip
9: Unable to create file: D:\hadoop2\hadoop-2.4.0-src\hadoop-yarn-project\hadoop-yarn\hadoop-yarn-server\ Hadoop-yarn-server-resourcemanager\target\test-classes\org\apache\hadoop\yarn\server\resourcemanager\rmapp\ Attempt\testrmappattempttransitions$testapplicationattempteventdispatcher.class:
The total length of the path and filename cannot exceed 260 characters
The system could not find the path specified. D:\hadoop2\hadoop-2.4.0-src.zip
2. Get the source code through MAVEN
It is necessary to note that when using MAVEN, you need to install JDK,PROTOC first, if not installed, you can refer to win7 How to install maven, install Protoc
(1) Enter Hadoop-2.4.0-src\hadoop-maven-plugins, run mvn install
- D:\HADOOP2\HADOOP-2.4.0-SRC\HADOOP-MAVEN-PLUGINS>MVN Install
Copy Code
Displays the following information
- [INFO] Scanning for projects ...
- [WARNING]
- [WARNING] Some problems were encountered while building the effective model for
- org.apache.hadoop:hadoop-maven-plugins:maven-plugin:2.4.0
- [WARNING] ' Build.plugins.plugin. (Groupid:artifactid) ' must is unique but found D
- uplicate Declaration of Plugin Org.apache.maven.plugins:maven-enforcer-plugin @
- org.apache.hadoop:hadoop-project:2.4.0, D:\hadoop2\hadoop-2.4.0-src\hadoop-proje
- Ct\pom.xml, line 1015, column 15
- [WARNING]
- [WARNING] It is highly recommended to fix these problems because they threaten t
- He stability of your build.
- [WARNING]
- [WARNING] For this reason, the future Maven versions might no longer support Buildin
- G such malformed projects.
- [WARNING]
- [INFO]
- [INFO] Using the builder Org.apache.maven.lifecycle.internal.builder.singlethrea
- Ded. Singlethreadedbuilder with a thread count of 1
- [INFO]
- [INFO]------------------------------------------------------------------------
- [INFO] Building Apache Hadoop Maven Plugins 2.4.0
- [INFO]------------------------------------------------------------------------
- [INFO]
- [INFO]---maven-antrun-plugin:1.7:run (create-testdirs) @ hadoop-maven-plugins
- ---
- [INFO] Executing tasks
- Main
- [INFO] Executed Tasks
- [INFO]
- [INFO]---maven-plugin-plugin:3.0:descriptor (default-descriptor) @ hadoop-mave
- N-plugins---
- [INFO] Using ' UTF-8 ' encoding to read Mojo metadata.
- [INFO] Applying Mojo extractor for language:java-annotations
- [INFO] Mojo Extractor for language:java-annotations found 2 Mojo descriptors.
- [INFO] Applying Mojo extractor for Language:java
- [INFO] Mojo extractor for Language:java found 0 Mojo descriptors.
- [INFO] Applying Mojo extractor for LANGUAGE:BSH
- [INFO] Mojo extractor for LANGUAGE:BSH found 0 Mojo descriptors.
- [INFO]
- [INFO]---maven-resources-plugin:2.2:resources (default-resources) @ Hadoop-mav
- En-plugins---
- [INFO] Using default encoding to copy filtered resources.
- [INFO]
- [INFO]---maven-compiler-plugin:2.5.1:compile (default-compile) @ hadoop-maven-
- Plugins---
- [INFO] Nothing to Compile-all classes is up to date
- [INFO]
- [INFO]---maven-plugin-plugin:3.0:descriptor (mojo-descriptor) @ hadoop-maven-p
- Lugins---
- [INFO] Using ' UTF-8 ' encoding to read Mojo metadata.
- [INFO] Applying Mojo extractor for language:java-annotations
- [INFO] Mojo Extractor for language:java-annotations found 2 Mojo descriptors.
- [INFO] Applying Mojo extractor for Language:java
- [INFO] Mojo extractor for Language:java found 0 Mojo descriptors.
- [INFO] Applying Mojo extractor for LANGUAGE:BSH
- [INFO] Mojo extractor for LANGUAGE:BSH found 0 Mojo descriptors.
- [INFO]
- [INFO]---maven-resources-plugin:2.2:testresources (default-testresources) @ ha
- Doop-maven-plugins---
- [INFO] Using default encoding to copy filtered resources.
- [INFO]
- [INFO]---maven-compiler-plugin:2.5.1:testcompile (default-testcompile) @ Hadoo
- P-maven-plugins---
- [INFO] No sources to compile
- [INFO]
- [INFO]---maven-surefire-plugin:2.16:test (default-test) @ hadoop-maven-plugins
- ---
- [INFO] No tests to run.
- [INFO]
- [INFO]---maven-jar-plugin:2.3.1:jar (default-jar) @ hadoop-maven-plugins---
- [INFO] Building Jar:d:\hadoop2\hadoop-2.4.0-src\hadoop-maven-plugins\target\had
- Oop-maven-plugins-2.4.0.jar
- [INFO]
- [INFO]---maven-plugin-plugin:3.0:addpluginartifactmetadata (default-addplugina
- rtifactmetadata) @ hadoop-maven-plugins---
- [INFO]
- [INFO]---maven-site-plugin:3.3:attach-descriptor (attach-descriptor) @ hadoop-
- Maven-plugins---
- [INFO]
- [INFO]---maven-install-plugin:2.3.1:install (default-install) @ hadoop-maven-p
- Lugins---
- [INFO] Installing D:\hadoop2\hadoop-2.4.0-src\hadoop-maven-plugins\target\hadoop
- -maven-plugins-2.4.0.jar to C:\Users\hyj\.m2\repository\org\apache\hadoop\hadoop
- -maven-plugins\2.4.0\hadoop-maven-plugins-2.4.0.jar
- [INFO] Installing D:\hadoop2\hadoop-2.4.0-src\hadoop-maven-plugins\pom.xml to C:
- \users\hyj\.m2\repository\org\apache\hadoop\hadoop-maven-plugins\2.4.0\hadoop-ma
- Ven-plugins-2.4.0.pom
- [INFO]------------------------------------------------------------------------
- [INFO] BUILD SUCCESS
- [INFO]------------------------------------------------------------------------
- [INFO] Total time:4.891 S
- [INFO] Finished at:2014-06-23t14:47:33+08:00
- [INFO] Final memory:21m/347m
- [INFO]------------------------------------------------------------------------
Copy Code
Sections are as follows:
(2) operation
- MVN eclipse:eclipse-dskiptests
Copy Code
Now, notice that we're in hadoop_home, and I'm D:\hadoop2\hadoop-2.4.0-src here.
Some of the information below
- [INFO]
- [INFO]------------------------------------------------------------------------
- [INFO] Reactor Summary:
- [INFO]
- [INFO] Apache Hadoop Main ......... ............... SUCCESS [0.684 S]
- [INFO] Apache Hadoop Project POM ......... ......... SUCCESS [0.720 S]
- [INFO] Apache Hadoop Annotations ......... .......... SUCCESS [0.276 S]
- [INFO] Apache Hadoop Project Dist POM ......... ..... SUCCESS [0.179 S]
- [INFO] Apache Hadoop assemblies ......... .......... SUCCESS [0.121 S]
- [INFO] Apache Hadoop Maven Plugins ........ ......... SUCCESS [1.680 S]
- [INFO] Apache Hadoop minikdc ......... ............. SUCCESS [1.802 S]
- [INFO] Apache Hadoop Auth ......... ............... SUCCESS [1.024 S]
- [INFO] Apache Hadoop Auth Examples ........ ......... SUCCESS [0.160 S]
- [INFO] Apache Hadoop Common ......... ............. SUCCESS [1.061 S]
- [INFO] Apache Hadoop NFS ......... ................ SUCCESS [0.489 S]
- [INFO] Apache Hadoop Common Project ......... ....... SUCCESS [0.056 S]
- [INFO] Apache Hadoop HDFS ......... ............... SUCCESS [2.770 S]
- [INFO] Apache Hadoop Httpfs ......... ............. SUCCESS [0.965 S]
- [INFO] Apache Hadoop HDFS bookkeeper Journal .... ..... SUCCESS [0.629 S]
- [INFO] Apache Hadoop Hdfs-nfs ......... ............ SUCCESS [0.284 S]
- [INFO] Apache Hadoop HDFS Project ......... ......... SUCCESS [0.061 S]
- [INFO] Hadoop-yarn ..... ....... ................... SUCCESS [0.052 S]
- [INFO] Hadoop-yarn-api .......... ................. SUCCESS [0.842 S]
- [INFO] Hadoop-yarn-common ......... ............... SUCCESS [0.322 S]
- [INFO] hadoop-yarn-server ......... ............... SUCCESS [0.065 S]
- [INFO] Hadoop-yarn-server-common ......... ......... SUCCESS [0.972 S]
- [INFO] Hadoop-yarn-server-nodemanager ......... ..... SUCCESS [0.580 S]
- [INFO] hadoop-yarn-server-web-proxy ......... ....... SUCCESS [0.379 S]
- [INFO] Hadoop-yarn-server-applicationhistoryservice ... SUCCESS [0.281 S]
- [INFO] Hadoop-yarn-server-resourcemanager ....... ..... SUCCESS [0.378 S]
- [INFO] hadoop-yarn-server-tests ......... .......... SUCCESS [0.534 S]
- [INFO] hadoop-yarn-client ......... ............... SUCCESS [0.307 S]
- [INFO] hadoop-yarn-applications ......... .......... SUCCESS [0.050 S]
- [INFO] Hadoop-yarn-applications-distributedshell ..... SUCCESS [0.202 S]
- [INFO] hadoop-yarn-applications-unmanaged-am-launcher .... SUCCESS [0.194 S]
- [INFO] hadoop-yarn-site .......... ................ SUCCESS [0.057 S]
- [INFO] hadoop-yarn-project ......... .............. SUCCESS [0.066 S]
- [INFO] hadoop-mapreduce-client ......... ........... SUCCESS [0.091 S]
- [INFO] Hadoop-mapreduce-client-core ......... ....... SUCCESS [1.321 S]
- [INFO] Hadoop-mapreduce-client-common ......... ..... SUCCESS [0.786 S]
- [INFO] hadoop-mapreduce-client-shuffle ......... ..... SUCCESS [0.456 S]
- [INFO] Hadoop-mapreduce-client-app ........ ......... SUCCESS [0.508 S]
- [INFO] hadoop-mapreduce-client-hs ......... ......... SUCCESS [0.834 S]
- [INFO] hadoop-mapreduce-client-jobclient ....... ..... SUCCESS [0.541 S]
- [INFO] hadoop-mapreduce-client-hs-plugins ....... ..... SUCCESS [0.284 S]
- [INFO] Apache Hadoop MapReduce Examples ........ ..... SUCCESS [0.851 S]
- [INFO] hadoop-mapreduce .......... ................ SUCCESS [0.099 S]
- [INFO] Apache Hadoop MapReduce streaming ....... ..... SUCCESS [0.742 S]
- [INFO] Apache Hadoop distributed Copy ......... ..... SUCCESS [0.335 S]
- [INFO] Apache Hadoop Archives ......... ............ SUCCESS [0.397 S]
- [INFO] Apache Hadoop rumen ......... .............. SUCCESS [0.371 S]
- [INFO] Apache Hadoop gridmix ......... ............. SUCCESS [0.230 S]
- [INFO] Apache Hadoop Data Join ......... ........... SUCCESS [0.184 S]
- [INFO] Apache Hadoop Extras ......... ............. SUCCESS [0.217 S]
- [INFO] Apache Hadoop Pipes ......... .............. SUCCESS [0.048 S]
- [INFO] Apache Hadoop OpenStack support ....... ....... SUCCESS [0.244 S]
- [INFO] Apache Hadoop Client ......... ............. SUCCESS [0.590 S]
- [INFO] Apache Hadoop mini-cluster ......... ......... SUCCESS [0.230 S]
- [INFO] Apache Hadoop Scheduler Load Simulator ...... SUCCESS [0.650 S]
- [INFO] Apache Hadoop Tools Dist ......... .......... SUCCESS [0.334 S]
- [INFO] Apache Hadoop Tools ......... .............. SUCCESS [0.042 S]
- [INFO] Apache Hadoop distribution ......... ......... SUCCESS [0.144 S]
- [INFO]------------------------------------------------------------------------
- [INFO] BUILD SUCCESS
- [INFO]------------------------------------------------------------------------
- [INFO] Total time:31.234 S
- [INFO] Finished at:2014-06-23t14:55:08+08:00
- [INFO] Final memory:84m/759m
- [INFO]------------------------------------------------------------------------
Copy Code
At this time, we have to download the source code down. At this point, we will see a noticeable increase in the file size.
<ignore_js_op>
3. Associated Eclipse Source
Join our program below
<ignore_js_op>hadoop2.2mapreduce example. rar (1.14 MB, download number: 7, Price: 1 cloud currency)
As shown, they were packaged
<ignore_js_op>
These two files, maxtemperature.zip for the MapReduce example, Mockito-core-1.8.5.jar the package referenced by the MapReduce example
(here need to explain is, MapReduce is 2.2, but does not affect the associated source code, just give you how to associate the source code)
After we unzip, import eclipse
(For importing projects unfamiliar, refer to the 0 basics to teach you how to import Eclipse projects)
<ignore_js_op>
After we import, see a lot of red line, these are actually no reference package, below we begin to solve these grammatical problems.
First, resolve the import jar package
(1) Introduction of Mockito-core-1.8.5.jar
(2) hadoop2.4 the jar files in the compiled package, the locations of these files are as follows:
Hadoop_home in the Share\hadoop folder, specifically I this position D:\hadoop2\hadoop-2.4.0\share\hadoop
Find the jar package inside, for example: the jar package in the Lib file, and the following jar packages are added to the BuildPath.
If you do not know how to add these jar packages for the reference package, refer to the Hadoop development approach summary and instructions.
(Note that we are here to introduce a compiled package that compiles the download hadoop--642.4.0.tar.gz
Link: http://pan.baidu.com/s/1c0vPjG0 Password: xj6l)
More package downloads can be found in the Hadoop family, Strom, Spark, Linux, Flume and other jar packages, installation package summary download
Second, the relevant source code
1. After we import the jar package, there is no error, as shown in
2. Source code not found
When we want to see how a class or function is implemented, the source file is not found through open call Hierarchy.
3.Attach Source
The above three places, we add in order, we select the package, click OK, OK, our work is finished.
Note: for Hadoop-2.2.0-src.zip is we above through maven download source code, and then compress the file, remember must be compressed file Zip form
4. Check the source code after verifying the association
We perform the above operation again, via the open call Hierarchy
See what follows
Then we double-click the main class, The Scarlet Letter section, and we see the following:
>
Problem:
Careful classmate, we have a problem in this, because we see a. class file instead of a. java file. Then he will not be the same as what we see. java files that.
In fact, is the same, interested students, can be verified.
Next article:
How to view and read hadoop2.4 source code through eclipse