Linux 编译 OpenJDK8

OpenJDK 有些组成部分是用 C++ 编写的,更多的代码则是使用 Java 自身实现的,因此编译这些 Java 代码需要用到一个可用的 JDK,官方称它为 Boot JDK。 如果编译 OpenJDK8,Boot JDK 可以是 OpenJDK7,也可以是 OracleJDK7,或者更早的版本。

准备工作

  1. 安装 Mercurial
1
apt-get install mercurial
  1. 用 Mercurial 下载
1
hg clone http://hg.openjdk.java.net/jdk8u/jdk8u
  1. 执行脚本
1
2
cd jdk8u &&
bash get_source.sh

开始编译

  1. 安装 Boot JDK

  2. 解压缩

1
tar -zxvf zulu7.31.0.5-ca-jdk7.0.232-linux_x64.tar.gz
  1. 改名
1
mv zulu7.31.0.5-ca-jdk7.0.232-linux_x64.tar.gz jdk7.0.232
  1. 配置用户环境变量
1
vi /etc/profile
  1. 添加如下语句
1
2
3
4
5
6
7
JAVA_HOME=/usr/local/java/jdk7.0.232
JRE_HOME=/usr/local/java/jdk7.0.232
PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/bin

export JAVA_HOME
export JRE_HOME
export PATH
  1. 使用户环境变量生效
1
source /etc/profile
  1. 测试是否安装成功
1
2
3
4
root@ubuntu:/usr/local/jdk8u-dev# java -version
openjdk version "1.7.0_232"
OpenJDK Runtime Environment (Zulu 7.31.0.5-CA-linux64) (build 1.7.0_232-b6)
OpenJDK 64-Bit Server VM (Zulu 7.31.0.5-CA-linux64) (build 24.232-b6, mixed mode)
  1. 安装依赖

安装依赖

1
2
apt-get install build-essential unzip zip libx11-dev libxext-dev libxrender-dev \
libxtst-dev libxt-dev libcups2-dev libfontconfig1-dev libasound2-dev libfreetype6-dev
  1. 检查依赖
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
bash configure
====================================================
A new configuration has been successfully created in
/usr/local/jdk8u-dev/build/linux-x86_64-normal-server-release
using default settings.

Configuration summary:
* Debug level: release
* JDK variant: normal
* JVM variants: server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64

Tools summary:
* Boot JDK: openjdk version "1.7.0_232" OpenJDK Runtime Environment (Zulu 7.31.0.5-CA-linux64) (build 1.7.0_232-b6) OpenJDK 64-Bit Server VM (Zulu 7.31.0.5-CA-linux64) (build 24.232-b6, mixed mode) (at /usr/local/java/jdk7.0.232)
* Toolchain: gcc (GNU Compiler Collection)
* C Compiler: Version 7.4.0 (at /usr/bin/gcc)
* C++ Compiler: Version 7.4.0 (at /usr/bin/g++)

Build performance summary:
* Cores to use: 1
* Memory limit: 962 MB
  1. 编译即可
1
make all

参考网址:

How can i install jdk7 on ubuntu 18.04 lts 64bit

JVM-Ubuntu18.04.1下编译OpenJDK8

评论