Download source code apache Download address : http://archive.apache.org/dist
<http://archive.apache.org/dist>/(apache We have everything at this address , Very convenient )
hadoop 1.1.2 download linux edition .tar.gz file After downloading , decompression , get into src binding
Create source project eclipse newly build web project project because hadoop Useful to J2EE 's bag , establish java project Project can only provide J2SE 's bag .
Remember to change the code to UTF-8, Java Compiler Change to 1.6
Import source code Create in project Source Folder folder core After decompressing src\core Next org Copy to eclipse Of core lower
After decompressing src\core Next core-default.xml( After the configuration file is compiled, it must be class lower ) Copy to eclipse Project's src lower
( After this step, the code will report an error , In the future, we need to jar Import )
examples,hdfs,mapred,test,tools with core Same operation test,tools and examples No replication required xml configuration file
Import jar Right click item Builde Path stay Libraries in choice Add External JARs Import hadoop After decompression, all the
jar (hadoop-core-1.1.2.jar etc. ) Import root directory lib All of them jar (asm-3.2.jar etc. ) Import
root directory src\test\lib All jar thus hadoop Source code jar Import all , It will be found that most of the source code no longer reports errors , Prompt in error reporting class
...tools.ant.... Cannot load to
We still need to go http://archive.apache.org/dist <http://archive.apache.org/dist>/ download ant
Root directory under ant-current-bin.zip
<http://archive.apache.org/dist/ant/ant-current-bin.zip> file Under the root directory after importing and decompressing lib All of jar
If you are eclipse Items created in will also report errors sun Related package not found , because eclipse Not used by default in sun Wait for a special bag (myeclipse no problem )
We need to add it manually : stay Builde Path Of Libraries Of JRE System.. Next Access rules add to
Read the source code method : See startup script Root directory lib/start-all.sh The first thing to do in the script is config Script environment variable configuration and other operations And then there was implement
dfs and mapred stay start-dfs.sh Can be seen in To start dfs Daemons , It's on namenode datanode
Found in project NameNode(org/apache/hadoop/hdfs/server/namenode/) Recommended Ctrl+Shift+R
Search , It's more convenient .
stay NameNode There is one at the bottom main method , View from this starting point hdfs Source code of , You can see the way to go first createNameNode -》init wait
As for other package source code reading, the same is true .