在Linux上編譯OpenJDK7源碼 | Compile OpenJDK7 source code on CentOS 6.5

 # 軟件環境丨Software Environment

  • OS:CentOS 6.5
  • JDK: OpenJDK-7u40 

 # 準備工做丨Preparation

  1. 下載源碼包 | Download source code package 
    OpenJDK Source Releases
  2. 解壓源碼包 | Decompress the packagehtml

    # unzip openjdk-7u40-fcs-src-b43-26_aug_2013.zip
    • hotspot 虛擬機實現,大部分是C/C++代碼
    • jdk Java核心類庫目錄,位於 jdk/src/share/classes
    • langtools 一些編譯工具

    安裝依賴 | 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
  3. 安裝freetype | install freetype
  4. # ./configure && make && make install
  5. 安裝ant | install ant
  6. # ln -s /usr/local/apache-ant-1.9.4/bin/ant /usr/bin/ant
  7. 安裝JDK(若是已有則沒必要從新安裝) | install JDK(optional if already installed)
    Sun JDK或Open JDK都可,過程略.

 # 環境配置丨Environment Configuration

編輯文件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]#

 # 測試驗證丨Testing & Verification

  • 一個測試類Test.java
    /**
    * 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源碼
    進入目錄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文件並運行會看到以下輸出:

在CentOS 6.5上編譯OpenJDK7源碼 | Compile OpenJDK7 source code on CentOS 6.5 - Bob.Z - 斷塵居

enjoy them:Dui

 

 # 參考資料丨Reference

 

-EOF-

相關文章
相關標籤/搜索