码迷,mamicode.com
首页 > 其他好文 > 详细

CentOS 6.9 Minimal 编译OpenJDK 7

时间:2018-05-01 10:42:19      阅读:399      评论:0      收藏:0      [点我收藏+]

标签:amd   建议   red   level   最佳实践   latest   sci   sse   conf   

今天学习《深入理解Java虚拟机:JVM高级特性与最佳实践》一书,并动手在Linux系统上编译OpenJDK 7,初次搞不太顺利,特记录下编译操作细节。

一、前期准备

约定:工具默认安装目录是/usr/local/,若有源码,则源码存放在/usr/local/src/目录下。

1、OpenJDK

下载OpenJDK 7,地址:http://download.java.net/openjdk/jdk7/promoted/b147/openjdk-7-fcs-src-b147-27_jun_2011.zip,文件校验码:http://download.java.net/openjdk/jdk7/promoted/b147/openjdk-7-fcs-src-b147-27_jun_2011.md5

wget http://download.java.net/openjdk/jdk7/promoted/b147/openjdk-7-fcs-src-b147-27_jun_2011.zip   # 下载

unzip openjdk-7-fcs-src-b147-27_jun_2011.zip   # 解压

mv openjdk openjdk7  # 更改目录名

2、FreeType

笔者使用的是freetype-2.4.0.tar.gz,下载地址:https://sourceforge.net/projects/freetype/files/freetype2/2.4.0/

tar -zxvf freetype-2.4.0.tar.gz    # 解压

cd freetype-2.4.0

./configure && make && make install    # 编译安装

3、Apache Ant

笔者使用的是apache-ant-1.9.7-bin.tar.gz,下载地址:https://archive.apache.org/dist/ant/binaries/

tar -zxvf apache-ant-1.9.7-bin.tar.gz  # 解压

mv apache-ant-1.9.7 /usr/local/

ln -s /usr/local/apache-ant-1.9.7/bin/ant  /usr/bin/ant  # 软链接到bin

4、BootstrapJDK

笔者使用的是jdk-6u45-linux-x64,因为源码更多是使用Java写的,因此需要使用一个可用的JDK去编译(详见深入理解Java虚拟机第一章),OpenJDK解压目录下有个README-builds.html<OpenJDK Build README>,建议详看一遍,文档说使用JDK 6

下载jdk-6u45-linux-x64.bin,下载地址:http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase6-419409.html

./jdk-6u45-linux-x64.bin    # 解压

mv jdk1.6.0_45 /usr/local/  # 移动目录

5、编译需要的相关工具

yum -y install gcc gcc-c++ alsa-lib alsa-lib-devel libXrender libXrender-devel libXi-devel libXt-devel libXtst-devel cups cups-devel

二、配置环境变量

vim /etc/profile  # 在末尾加入以下内容注意各个目录Path

# openjdk 7 build
export ANT_HOME=/usr/local/apache-ant-1.9.7
export ALT_FREETYPE_HEADERS_PATH=/usr/local/include/freetype2
export ALT_FREETYPE_LIB_PATH=/usr/local/lib
export ALT_DROPS_DIR=/usr/local/src/openjdk7/drop
export ALT_BOOTDIR=/usr/local/jdk1.6.0_45
export ALT_JDK_IMPORT_PATH=/usr/local/jdk1.6.0_45
export ALT_OUTPUTDIR=/usr/local/openjdk7
export LANG=C
export HOTSPOT_BUILD_JOBS=8
export ALT_PARALLEL_COMPILE_JOBS=8
export SKIP_COMPARE_IMAGES=true
export USE_PRECOMPILED_HEADER=true
export ALLOW_DOWNLOADS=true
export SKIP_DEBUG_BUILD=false
export SKIP_FASTDEBUG_BUILD=true
export DEBUG_NAME=debug
unset JAVA_HOME
unset CLASSPATH

  :wq  # 写入磁盘

  source /etc/profile  # 刷新环境变量配置使之生效,建议echo下几个配置项确认生效,例:echo $LANG

  cd openjdk7  # 进入OpenJDK解压目录

  make sanity   # 检查之前的配置是否正确,若无错误(Sanity check passed.)则OK,下面是笔者的执行结果宫参考

技术分享图片
[root@dsp-centos-3-6_9 openjdk7]# make sanity
( cd  ./jdk/make &&           make sanity HOTSPOT_IMPORT_CHECK=false JDK_TOPDIR=/usr/local/src/openjdk7/jdk JDK_MAKE_SHARED_DIR=/usr/local/src/openjdk7/jdk/make/common/shared EXTERNALSANITYCONTROL=true SOURCE_LANGUAGE_VERSION=7 TARGET_CLASS_VERSION=7 MILESTONE=internal BUILD_NUMBER=b00 JDK_BUILD_NUMBER=b00 FULL_VERSION=1.7.0-internal-debug-root_2018_05_01_00_10-b00 PREVIOUS_JDK_VERSION=1.6.0 JDK_VERSION=1.7.0 JDK_MKTG_VERSION=7 JDK_MAJOR_VERSION=1 JDK_MINOR_VERSION=7 JDK_MICRO_VERSION=0 PREVIOUS_MAJOR_VERSION=1 PREVIOUS_MINOR_VERSION=6 PREVIOUS_MICRO_VERSION=0 ARCH_DATA_MODEL=64 VARIANT=DBG DEBUG_CLASSFILES=true COOKED_BUILD_NUMBER=0 ANT_HOME="/usr/local/apache-ant-1.9.7" ALT_OUTPUTDIR=/usr/local/openjdk7 ALT_LANGTOOLS_DIST=/usr/local/openjdk7/langtools/dist ALT_CORBA_DIST=/usr/local/openjdk7/corba/dist ALT_JAXP_DIST=/usr/local/openjdk7/jaxp/dist ALT_JAXWS_DIST=/usr/local/openjdk7/jaxws/dist ALT_HOTSPOT_IMPORT_PATH=/usr/local/openjdk7/hotspot/import BUILD_HOTSPOT=true ; )
make[1]: Entering directory `/usr/local/src/openjdk7/jdk/makemake[1]: Leaving directory `/usr/local/src/openjdk7/jdk/make
Build Machine Information:
   build machine = dsp-centos-3-6_9

Build Directory Structure:
   CWD = /usr/local/src/openjdk7
   TOPDIR = .
   LANGTOOLS_TOPDIR = ./langtools
   JAXP_TOPDIR = ./jaxp
   JAXWS_TOPDIR = ./jaxws
   CORBA_TOPDIR = ./corba
   HOTSPOT_TOPDIR = ./hotspot
   JDK_TOPDIR = ./jdk

Build Directives:
   BUILD_LANGTOOLS = true 
   BUILD_JAXP = true 
   BUILD_JAXWS = true 
   BUILD_CORBA = true 
   BUILD_HOTSPOT = true 
   BUILD_JDK    = true 
   DEBUG_CLASSFILES =  
   DEBUG_BINARIES =  

Hotspot Settings: 
      HOTSPOT_BUILD_JOBS  = 8 
      HOTSPOT_OUTPUTDIR   = /usr/local/openjdk7/hotspot/outputdir 
      HOTSPOT_EXPORT_PATH = /usr/local/openjdk7/hotspot/import 
 



Bootstrap Settings:
  BOOTDIR = /usr/local/jdk1.6.0_45
    ALT_BOOTDIR = /usr/local/jdk1.6.0_45
  BOOT_VER = 1.6.0 [requires at least 1.6]
  OUTPUTDIR = /usr/local/openjdk7
    ALT_OUTPUTDIR = /usr/local/openjdk7
  ABS_OUTPUTDIR = /usr/local/openjdk7
 
Build Tool Settings:
  SLASH_JAVA = /NOT-SET
    ALT_SLASH_JAVA = 
  VARIANT = DBG
  JDK_DEVTOOLS_DIR = /NOT-SET/devtools
    ALT_JDK_DEVTOOLS_DIR = 
  ANT_HOME = /usr/local/apache-ant-1.9.7
  UNIXCOMMAND_PATH = /bin/
    ALT_UNIXCOMMAND_PATH = 
  COMPILER_PATH = /usr/bin/
    ALT_COMPILER_PATH = 
  DEVTOOLS_PATH = /usr/bin/
    ALT_DEVTOOLS_PATH = 
  UNIXCCS_PATH = /usr/ccs/bin/
    ALT_UNIXCCS_PATH = 
  USRBIN_PATH = /usr/bin/
    ALT_USRBIN_PATH = 
  COMPILER_NAME = GCC4
  COMPILER_VERSION = GCC4
  CC_VER = 4.4.7 [requires at least 4.3.0]
  ZIP_VER = 3.0 [requires at least 2.2]
  UNZIP_VER = 6.00 [requires at least 5.12]
  ANT_VER = 1.9.7 [requires at least 1.7.1]
  TEMPDIR = /usr/local/openjdk7/tmp
 
Build Directives:
  OPENJDK = true
  USE_HOTSPOT_INTERPRETER_MODE = 
  PEDANTIC = 
  DEV_ONLY = 
  NO_DOCS = 
  NO_IMAGES = 
  TOOLS_ONLY = 
  INSANE = 
  COMPILE_APPROACH = parallel
  PARALLEL_COMPILE_JOBS = 8
    ALT_PARALLEL_COMPILE_JOBS = 8
  FASTDEBUG = 
  COMPILER_WARNINGS_FATAL = false
  COMPILER_WARNING_LEVEL = 
  SHOW_ALL_WARNINGS = 
  INCREMENTAL_BUILD = false
  CC_HIGHEST_OPT = 
  CC_HIGHER_OPT = 
  CC_LOWER_OPT = 
  CXXFLAGS =  -g -fPIC -DCC_NOEX -W -Wall  -Wno-unused -Wno-parentheses -fno-omit-frame-pointer -D_LITTLE_ENDIAN  
  CFLAGS =  -g   -fno-strict-aliasing -fPIC -W -Wall  -Wno-unused -Wno-parentheses -pipe -fno-omit-frame-pointer -D_LITTLE_ENDIAN  
  BOOT_JAVA_CMD = /usr/local/jdk1.6.0_45/bin/java -XX:-PrintVMOptions -XX:+UnlockDiagnosticVMOptions -XX:-LogVMOutput -Xmx512m -Xms512m -XX:PermSize=32m -XX:MaxPermSize=160m
  BOOT_JAVAC_CMD = /usr/local/jdk1.6.0_45/bin/javac  -J-XX:ThreadStackSize=1536 -J-XX:-PrintVMOptions -J-XX:+UnlockDiagnosticVMOptions -J-XX:-LogVMOutput -J-Xmx512m -J-Xms512m -J-XX:PermSize=32m -J-XX:MaxPermSize=160m -encoding ascii -source 6 -target 6 -XDignore.symbol.file=true
  BOOT_JAR_CMD = /usr/local/jdk1.6.0_45/bin/jar
  BOOT_JARSIGNER_CMD = /usr/local/jdk1.6.0_45/bin/jarsigner
  JAVAC_CMD = /usr/local/jdk1.6.0_45/bin/java -XX:-PrintVMOptions -XX:+UnlockDiagnosticVMOptions -XX:-LogVMOutput -Xmx512m -Xms512m -XX:PermSize=32m -XX:MaxPermSize=160m -Xbootclasspath/p:/usr/local/openjdk7/langtools/dist/bootstrap/lib/javac.jar -jar /usr/local/openjdk7/langtools/dist/bootstrap/lib/javac.jar  -g -source 7 -target 7 -encoding ascii -Xbootclasspath:/usr/local/openjdk7/classes 
  JAVAH_CMD = /usr/local/jdk1.6.0_45/bin/java -XX:-PrintVMOptions -XX:+UnlockDiagnosticVMOptions -XX:-LogVMOutput -Xmx512m -Xms512m -XX:PermSize=32m -XX:MaxPermSize=160m -Xbootclasspath/p:/usr/local/openjdk7/langtools/dist/bootstrap/lib/javah.jar:/usr/local/openjdk7/langtools/dist/bootstrap/lib/javac.jar -jar /usr/local/openjdk7/langtools/dist/bootstrap/lib/javah.jar -bootclasspath /usr/local/openjdk7/classes
  JAVADOC_CMD = /usr/local/jdk1.6.0_45/bin/java -XX:-PrintVMOptions -XX:+UnlockDiagnosticVMOptions -XX:-LogVMOutput -Xmx512m -Xms512m -XX:PermSize=32m -XX:MaxPermSize=160m -Xbootclasspath/p:/usr/local/openjdk7/langtools/dist/bootstrap/lib/javadoc.jar:/usr/local/openjdk7/langtools/dist/bootstrap/lib/javac.jar:/usr/local/openjdk7/langtools/dist/bootstrap/lib/doclets.jar -jar /usr/local/openjdk7/langtools/dist/bootstrap/lib/javadoc.jar -bootclasspath /usr/local/openjdk7/classes
 
Build Platform Settings:
  USER = root
  PLATFORM = linux
  ARCH = amd64
  LIBARCH = amd64
  ARCH_FAMILY = amd64
  ARCH_DATA_MODEL = 64
  ARCHPROP = amd64
  ALSA_VERSION = 1.1.0
  OS_VERSION = 2.6.32-696.16.1.el6.x86_64 [requires at least 2.6]
  OS_VARIANT_NAME = RedHat
  OS_VARIANT_VERSION = 
  MB_OF_MEMORY = 1861
 
GNU Make Settings:
  MAKE = make
  MAKE_VER = 3.81 [requires at least 3.81]
  MAKECMDGOALS = sanity
  MAKEFLAGS = w
  SHELL = /bin/sh
 
Target Build Versions:
  JDK_VERSION = 1.7.0
  MILESTONE = internal
  RELEASE = 1.7.0-internal-debug
  FULL_VERSION = 1.7.0-internal-debug-root_2018_05_01_00_10-b00
  BUILD_NUMBER = b00
 
External File/Binary Locations:
  USRJDKINSTANCES_PATH = /opt/java
  BUILD_JDK_IMPORT_PATH = /NOT-SET/re/jdk/1.7.0/promoted/latest/binaries
    ALT_BUILD_JDK_IMPORT_PATH = 
  JDK_IMPORT_PATH = /usr/local/jdk1.6.0_45
    ALT_JDK_IMPORT_PATH = /usr/local/jdk1.6.0_45
  LANGTOOLS_DIST = /usr/local/openjdk7/langtools/dist
    ALT_LANGTOOLS_DIST = /usr/local/openjdk7/langtools/dist
  CORBA_DIST = /usr/local/openjdk7/corba/dist
    ALT_CORBA_DIST = /usr/local/openjdk7/corba/dist
  JAXP_DIST = /usr/local/openjdk7/jaxp/dist
    ALT_JAXP_DIST = /usr/local/openjdk7/jaxp/dist
  JAXWS_DIST = /usr/local/openjdk7/jaxws/dist
    ALT_JAXWS_DIST = /usr/local/openjdk7/jaxws/dist
  HOTSPOT_DOCS_IMPORT_PATH = /usr/local/openjdk7/hotspot/import/docs
    ALT_HOTSPOT_DOCS_IMPORT_PATH = 
  HOTSPOT_IMPORT_PATH = /usr/local/openjdk7/hotspot/import
    ALT_HOTSPOT_IMPORT_PATH = /usr/local/openjdk7/hotspot/import
  HOTSPOT_SERVER_PATH = /usr/local/openjdk7/hotspot/import/jre/lib/amd64/server
    ALT_HOTSPOT_SERVER_PATH = 
  CACERTS_FILE = ./../src/share/lib/security/cacerts
    ALT_CACERTS_FILE = 
  CUPS_HEADERS_PATH = /usr/include
    ALT_CUPS_HEADERS_PATH = 
 
OpenJDK-specific settings:
  FREETYPE_HEADERS_PATH = /usr/local/include/freetype2
    ALT_FREETYPE_HEADERS_PATH = /usr/local/include/freetype2
  FREETYPE_LIB_PATH = /usr/local/lib
    ALT_FREETYPE_LIB_PATH = /usr/local/lib
 
Previous JDK Settings:
  PREVIOUS_RELEASE_PATH = USING-PREVIOUS_RELEASE_IMAGE
    ALT_PREVIOUS_RELEASE_PATH = 
  PREVIOUS_JDK_VERSION = 1.6.0
    ALT_PREVIOUS_JDK_VERSION = 
  PREVIOUS_JDK_FILE = 
    ALT_PREVIOUS_JDK_FILE = 
  PREVIOUS_JRE_FILE = 
    ALT_PREVIOUS_JRE_FILE = 
  PREVIOUS_RELEASE_IMAGE = /usr/local/jdk1.6.0_45
    ALT_PREVIOUS_RELEASE_IMAGE = 


Sanity check passed.
View Code

三、编译操作

   make 2>&1 | tee $ALT_OUTPUTDIR/build.log  # 编译,标准错误输出stderr重定向到标准输出stdout,将编译过程数据重定向到文件保存。

  若编译失败,重新编译前先执行:make clean

  若编译成功,提示信息如下:

-- Build times ----------
Target debug_build
Start 2018-04-30 23:30:30
End 2018-04-30 23:45:05
00:01:45 corba
00:03:32 hotspot
00:00:18 jaxp
00:00:24 jaxws
00:08:05 jdk
00:00:31 langtools
00:14:35 TOTAL
-------------------------

四、验证

  进入/usr/local/openjdk7/bin(即$ALT_OUTPUTDIR/bin)目录,执行:./java -version

[root@dsp-centos-2-6_9 bin]# ./java -version
openjdk version "1.7.0-internal-debug"
OpenJDK Runtime Environment (build 1.7.0-internal-debug-root_2018_04_30_20_26-b00)
OpenJDK 64-Bit Server VM (build 21.0-b17-jvmg, mixed mode)

五、笔者碰到的问题

  1、java.lang.RuntimeException: time is more than 10 years from present

    修改jdk/src/share/classes/java/util/CurrencyData.properties,将日期改为十年以内,JDK的Bug。

  108行改为: AZ=AZM;2009-12-31-20-00-00;AZN,接下来的377、439、529、555行类似修改保存,重新编译。

2、/usr/local/openjdk7-debug/jaxws/build/xml_generated/build-drop-jaf_src.xml:96: Redirection detected from https to http. Protocol switch unsafe, not allowed.

  原因是jdk7-jaf-2010_08_19.zip这个包下载不了导致的,解决方案:

将以下三个文件下载后置于OpenJDK解压后根目录下的drop目录下,并在环境变量中加入配置:export ALT_DROPS_DIR=/usr/local/src/openjdk7/drop # 注意目录Path

jdk7-jaf-2010_08_19.zip,下载地址:https://netix.dl.sourceforge.net/project/jdk7src/input-archives/jdk7-jaf-2010_08_19.zip

jdk7-jaxws2_2_4-b03-2011_05_27.zip,下载地址:http://download.java.net/glassfish/components/jax-ws/openjdk/jdk7/jdk7-jaxws2_2_4-b03-2011_05_27.zip 

jaxp145_01.zip,下载地址:http://download.java.net/jaxp/1.4.5/jaxp145_01.zip

六、参考资料:

  《深入理解Java虚拟机:JVM高级特性与最佳实践》

  [深入理解Java虚拟机]第一章实战 自己编译JDK

  ubuntu13 编译openjdk7的问题并解决

  java-编译openJdk

  openjdk7 源码下载

JDK源码下载

OpenJDK8 Windows编译

CentOS 6.9 Minimal 编译OpenJDK 7

标签:amd   建议   red   level   最佳实践   latest   sci   sse   conf   

原文地址:https://www.cnblogs.com/gotodsp/p/8975387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!