ubuntu16.04编译openjdk7

1.修改ubuntu软件源

清华大学开源软件镜像站

  1. 将ubuntu软件源配置文件sources.list修改为sources.list.bak
  2. 新建sources.list,将清华大学镜像粘贴进去
  3. 更新apt软件列表
cd /etc/apt/
mv sources.list sources.list.bak

cat > sources.list <<EOF
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
EOF

apt update

2.下载编译openjdk需要的依赖

《深入理解java虚拟机》给出的依赖为:

apt install build-essential gawk m4 openjdk-6-jdk libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev x11proto-print-dev binutils libmotif3 libmotif-dev ant

其中,openjdk-6-jdk 是不能直接apt安装的,我们可以直接到openjdk,选择合适的包下载。下载前还需要注册一个Oracle帐号。下载好jdk-6u45-linux-x64.bin后复制到想要的目录并运行,相同目录下就会创建一个包含有jdk的文件夹。

libmotif3也无法直接安装,在该网站我找到了答案:

This is a transitional package as the new packages libmrm4, libuil4
and libxm4 are binary compatible with libmotif3. It can safely be
removed.

libmotif3只是一个过渡产物,现在被libmrm4, libuil4, libxm4替代了。

网上查阅的依赖如下:

apt install build-essential gawk m4 libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-dev x11proto-print-dev binutils libmotif-common ant
apt install libmrm4 libuil4 libxm4

上面安装依赖的命令我都运行过

3.下载openjdk7源码

我是在gitee上找的源码:https://gitee.com/huan4j/jdk7.git

cd /usr
git clone https://gitee.com/huan4j/jdk7.git
mv jdk7 openjdk

4.安装openjdk6

第二步时下载的openjdk-6-jdk,拷贝到/usr/java目录下并执行

mkdir /usr/java
cd /usr/java
./jdk-6u45-linux-x64.bin

5.配置编译参数

修改配置文件:

vim /etc/profile

在后面追加如下内容:

##
export LANG=C
#BootStrap-JDK
export ALT_BOOTDIR=/usr/java/jdk1.6.0_45
#OracleJDK
export ALT_JDK_IMPORT_PATH=/usr/java/jdk1.6.0_45
#
export ALLOW_DOWNLOADS=true
#与你的CPU核数对应即可
export HOTSPOT_BUILD_JOBS=3
export ALT_PARALLEL_COMPILE_JOBS=3
#
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

末尾出现Sanity check passed. 则验证通过。

编译

source /etc/profile

在这里插入图片描述

我给虚拟机分配了3核,编译耗时14分钟

7.验证编译结果

cd /usr/openjdk/build/j2sdk-image
ls -l

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值