ubuntu16.04编译JDK7

1.安装依赖
sudo apt-get update
sudo apt-get install build-essential gawk m4 libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev x11proto-print-dev binutils libmotif-common ant
2.下载源码和oracle的jdk6

(1) jdk6下载
本文使用jdk-6u32-linux-x64.bin
(2) jdk7源码
本文使用 openjdk-7-fcs-src-b147-27_jun_2011.zip

3.解压源码

将openjdk-7-fcs-src-b147-27_jun_2011.zip发送到当前用户的home目录下

cd ~
sudo apt-get install unar
sudo unar openjdk-7-fcs-src-b147-27_jun_2011.zip
sudo mv ~/openjdk /usr/openjdk
4.运行jdk-6u32-linux-x64.bin
sudo chmod u+x jdk-6u32-linux-x64.bin
sudo ./jdk-6u32-linux-x64.bin
cd /usr
sudo mkdir java
sudo mv ~/jdk1.6.0_32 /usr/java/
5.配置 /etc/profile文件
sudo vim /etc/profile

请注释掉里面的JAVA_HOME和CLASSPATH
并添加以下内容

##
export LANG=C
#BootStrap-JDK
export ALT_BOOTDIR=/usr/java/jdk1.6.0_32
#OracleJDK
export ALT_JDK_IMPORT_PATH=/usr/java/jdk1.6.0_32
#
export ALLOW_DOWNLOADS=true
#与你的CPU核数对应即可
export HOTSPOT_BUILD_JOBS=1
export ALT_PARALLEL_COMPILE_JOBS=1
#
export USE_PRECOMPILED_HEADER=true
#
export BUILD_LANGTOOLS=true
export BUILD_JAXWS=false
#export BUILD_JAXP=false
#export BUILD_CORBA=false
export BUILD_HOTSPOT=true

export BUILD_JDK=true

export SKIP_COMPARE_IMAGES=true
#
BUILD_DEPLOY=false
#
BUILD_INSTALL=false
#
export ALT_OUTPUTDIR=/usr/openjdk/build
#
unset JAVA_HOME
unset CLASSPATH
#
make 2>&1 | tee $ALT_OUTPUTDIR/build.log
6.编译源码
cd /usr/openjdk/
make sanity
验证通过
source /etc/profile

每次编译出错都应该

make clean
7.编译过程出现的错误
#错误
echo "*** This OS is not supported:" `uname -a`; exit 1;
#解决
sudo vim openjdk/hotspot/make/linux/Makefile
注释掉以下三行
#ifeq ($(DISABLE_HOTSPOT_OS_VERSION_CHECK)$(EMPTY_IF_NOT_SUPPORTED),)
# $(QUIETLY) >&2 echo "*** This OS is not supported:" `uname -a`; exit 1;
#endif
#错误
Error:/openjdk/hotspot/src/share/vm/oops/constantPoolOop.cpp:272:39: 
error: converting 'false' to pointer type 'methodOop' [-Werror=conversion-null]
#解决
sudo vim /usr/openjdk/hotspot/src/share/vm/oops/constantPoolOop.cpp
将return false  改为 return NULL
#错误
/usr/openjdk/hotspot/src/share/vm/opto/loopnode.cpp:896:49: 
error: converting 'false' to pointer type 'Node*' [-Werror=conversion-null]
#解决
sudo vim /usr/openjdk/hotspot/src/share/vm/opto/loopnode.cpp
将return false  改为 return NULL
#错误
gcc: error: unrecognized command line option '-mimpure-text'
#解决
sudo vim /usr/openjdk/jdk/make/common/shared/Compiler-gcc.gmk
去掉或者注释掉 -mimpure-text
#错误
Error: time is more than 10 years from present: 1136059200000
#解决
sudo vim /usr/openjdk/jdk/src/share/classes/java/util/CurrencyData.properties
将所有时间都改成你当前年份的前一年
#错误
与javax/sound/jsoundalsa有关的错误
# 解决
sudo vim /usr/openjdk/jdk/make/javax/sound/jsoundalsa/Makefile
将LDFLAGS += -lasound   修改为 OTHER_LDLIBS += -lasound
#错误
error:"__LEAF"redefined [-Werror]

解决: __LEAF定义问题解决

8.编译成功
编译完成

你可能感兴趣的:(ubuntu16.04编译JDK7)