解壓源碼包 | Decompress the packagehtml
# unzip openjdk-7u40-fcs-src-b43-26_aug_2013.zip
安裝依賴 | Install dependencejava
# yum -y install gcc gcc-c++ alsa-lib alsa-lib-devel libXrender libXrender-devel libXi-devel libXt-devel libXtst-devel cups cups-devel
# ./configure && make && make install
# ln -s /usr/local/apache-ant-1.9.4/bin/ant /usr/bin/ant
編輯文件vim ~/.bash_profile
加入如下變量 | Modify the .bash_profile and set the variables belowlinux
export LANG="C" export ALT_BOOTDIR="/usr/java/jdk1.7.0_67/" export ANT_HOME="/usr/local/apache-ant-1.9.4" export ALT_FREETYPE_HEADERS_PATH="/usr/local/include/freetype2" export ALT_FREETYPE_LIB_PATH="/usr/local/lib" export ALLOW_DOWNLOADS=true export SKIP_DEBUG_BUILD=false export SKIP_FASTDEBUG_BUILD=true export DEBUG_NAME=debug unset JAVA_HOME unset CLASSPATH
使變量生效 | make the variables take effectc++
# source ~/.bash_profile
# 編譯源碼丨Compile Source Codeapache
測試環境是否健全 | Check environment if sane.vim
# make sanity
若是輸出如下內容則表示經過,能夠進行編譯。| if the environment is OK, it can be compiled.bash
Sanity check passed.
開始編譯 | start to compile use 'make' command工具
# make ARCH_DATA_MODEL=64
看到以下輸出則爲編譯成功 | It indicates that OpenJDK has been compiled successfully測試
>>>Finished making images @ Sat Nov 8 00:45:16 EST 2014 ... make[2]: Leaving directory `/usr/local/openjdk/jdk/make' ######################################################################## ##### Leaving jdk for target(s) sanity all docs images ##### ######################################################################## ##### Build time 00:10:15 jdk for target(s) sanity all docs images ##### ######################################################################## #-- Build times ---------- Target debug_build Start 2014-11-08 00:26:41 End 2014-11-08 00:45:16 00:02:11 corba 00:04:36 hotspot 00:00:24 jaxp 00:00:30 jaxws 00:10:15 jdk 00:00:39 langtools 00:18:35 TOTAL ------------------------- make[1]: Leaving directory `/usr/local/openjdk' [root@BobServerStation openjdk]#
/** * Author: Bob.Z * Date: 2014-11-08 */ public class Test{ public static void main(String[] args){ System.out.println("Hello OpenJDK~"); } }使用剛生成的JDK編譯:
# ./build/linux-amd64/bin/javac Test.java在當前目錄下會生成Test.class文件,而後運行便會看到輸出。
# ./build/linux-amd64/bin/java Test Hello OpenJDK~
jdk/src/share/classes/java/io
,而後修改PrintStream.java
/** * Prints a string. If the argument is <code>null</code> then the string * <code>"null"</code> is printed. Otherwise, the string's characters are * converted into bytes according to the platform's default character * encoding, and these bytes are written in exactly the manner of the * <code>{@link #write(int)}</code> method. * * @param s The <code>String</code> to be printed */ public void print(String s) { if (s == null) { s = "null"; } s = s + " This is OpenJdk7 compiled by Bob.Z!!!"; // 從新賦值 write(s); }接下來從新編譯JDK,從新編譯剛纔的Test.java文件並運行會看到以下輸出:
enjoy them:Dui
-EOF-