openjdk 1.8 源码编译

简介: openjdk 1.8 源码编译

编译环境


环境说明


Ubuntu 20.04.1 LTS


OpenJDK jdk8-b120


注意:Ubuntu 配置 apt 安装源为阿里源可以提高加载速度


设置 设置 apt 安装阿里源


1. 设置 apt 安装阿里源


sudo cp /ect/apt/sources.list /etc/apt/sources.list.bak


2. 添加阿里源


deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse


3. 更新源


sudo apt-get update
sudo apt-get upgrade


下载 jdk 源码到本地


官网地址:openjdk.java.net/


github 源码地址: github.com/openjdk/


我的下载地址: gitee.com/zhengsh/jdk


下载命令:


# 由于github 国内网络太慢我已经将 openjdk 代码同步到 gitee
~/javawork$ git clone https://gitee.com/zhengsh/jdk.git


执行编译


1. 安装 open-jdk-8


sudo apt-get install openjdk-8-jdk


2.编译代码


# 执行编译
bash ./configure


3.错误提示:


configure: error: Cannot find GNU make 3.81 or newer! Please put it in the path, or add e.g. MAKE=/opt/gmake3.81/make as argument to configure.


# 我的是 make 没有安装
sudo apt-get install make
#如果其它提示可以参考 java bug  https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8027567


4.错误提示:


configure: error: Could not find a C compiler. You might be able to fix this by running 'sudo apt-get install build-essential'.


# 安装 build-essential
sudo apt-get install build-essential


5.错误提示:


configure: error: Could not find all X11 headers (shape.h Xrender.h XTest.h Intrinsic.h). You might be able to fix this by running 'sudo apt-get install libX11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev'.


# 安装 libX11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev
# 注意 libx11-dev 的 X 是小写
sudo apt-get install libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev


6.错误提示:


configure: error: Could not find cups! You might be able to fix this by running 'sudo apt-get install libcups2-dev'.


# 安装 libcups2-dev
sudo apt-get install libcups2-dev


7.错误提示:


configure: error: Could not find freetype! You might be able to fix this by running 'sudo apt-get install libfreetype6-dev'.


# 安装 libfreetype6-dev
sudo apt-get install libfreetype6-dev


8.错误提示:


configure: error: Could not find alsa! You might be able to fix this by running 'sudo apt-get install libasound2-dev'.


# 安装 libasound2-dev
sudo apt-get install libasound2-dev


9.成功提示


Tools summary:
* Boot JDK:       openjdk version "1.8.0_275" OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~20.04-b01) OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)  (at /usr/lib/jvm/java-8-openjdk-amd64)
* C Compiler:     x86_64-linux-gnu-gcc-9 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (at /usr/bin/x86_64-linux-gnu-gcc-9)
* C++ Compiler:   x86_64-linux-gnu-g++-9 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (at /usr/bin/x86_64-linux-gnu-g++-9)
Build performance summary:
* Cores to use:   1
* Memory limit:   3936 MB
* ccache status:  not installed (consider installing)
Build performance tip: ccache gives a tremendous speedup for C++ recompilations.
You do not have ccache installed. Try installing it.
You might be able to fix this by running 'sudo apt-get install ccache'.


10.make all


# 错误提示,(解决方法降低 gcc 版本)
make[6]: *** [/home/zsh/javawork/jdk/hotspot/make/linux/makefiles/vm.make:297: precompiled.hpp.gch] Error 1
make[5]: *** [/home/zsh/javawork/jdk/hotspot/make/linux/makefiles/top.make:119: the_vm] Error 2
make[4]: *** [/home/zsh/javawork/jdk/hotspot/make/linux/Makefile:289: product] Error 2
make[3]: *** [Makefile:217: generic_build2] Error 2
make[2]: *** [Makefile:167: product] Error 2
make[1]: *** [HotspotWrapper.gmk:45: /home/zsh/javawork/jdk/build/linux-x86_64-normal-server-release/hotspot/_hotspot.timestamp] Error 2
make: *** [/home/zsh/javawork/jdk//make/Main.gmk:109: hotspot-only] Error 2
# gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# 安装 gcc-4.8 g++-4.8
sudo apt-get install -y gcc-4.8
sudo apt-get install -y g++-4.8
# 重新建立软连接
cd /usr/bin             #进入/usr/bin文件夹下
sudo rm -r gcc          #移除之前的软连接
sudo ln -sf gcc-4.8 gcc #建立gcc4.8的软连接
sudo rm -r g++
sudo ln -sf g++-4.8 g++
# 重新查询 gcc 版本
gcc --version 
gcc (Ubuntu 4.8.5-4ubuntu8) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


11.make all 成功提示信息


----- Build times -------
Start 2020-12-12 22:17:38
End   2020-12-12 22:51:31
00:00:54 corba
00:01:03 demos
00:04:57 docs
00:16:08 hotspot
00:01:06 images
00:00:35 jaxp
00:01:05 jaxws
00:06:49 jdk
00:00:54 langtools
00:00:21 nashorn
00:33:53 TOTAL
-------------------------
Finished building OpenJDK for target 'all'


编译成功


cd /javawork/jdk/build/linux-x86_64-normal-server-release/jdk/bin
    ./java -version
    # 到此 openjdk 编译成功
    openjdk version "1.8.0-internal"
    OpenJDK Runtime Environment (build 1.8.0-internal-zsh_2020_12_12_22_17-b00)
    OpenJDK 64-Bit Server VM (build 25.0-b62, mixed mode)


总结


  1. 其实我没有看特别教程, 就参考了,OpenJdk 中的 README 文件,然后结合提示解决问题 Google 解决问题。


  1. 系统要求,建议虚拟机在 4核心8G 内存不然过程比较漫长。


  1. 这些都是环境搭建层面上的东西,后续我将继续完善 openjdk 相关的笔记


相关文章
|
Java
JDK1.8源码下载及获取、导入IDEA阅读、配置JDK源码
本文是博主学习JDK源码的记录,希望对大家有所帮助。
2411 0
JDK1.8源码下载及获取、导入IDEA阅读、配置JDK源码
|
消息中间件 Apache RocketMQ
rocketmq客户端发送消息报错和超时问题
org.apache.rocketmq.remoting.exception.RemotingTimeoutException: wait response on the channel <10.0.21.69:10911> timeout, 1000(ms)、 closeChannel: close the connection to remote address
4617 1
rocketmq客户端发送消息报错和超时问题
|
Oracle Java 关系型数据库
Oracle jdk 的国内下载镜像
Oracle jdk 的国内下载镜像
50663 0
|
10月前
|
XML 安全 Java
【日志框架整合】Slf4j、Log4j、Log4j2、Logback配置模板
本文介绍了Java日志框架的基本概念和使用方法,重点讨论了SLF4J、Log4j、Logback和Log4j2之间的关系及其性能对比。SLF4J作为一个日志抽象层,允许开发者使用统一的日志接口,而Log4j、Logback和Log4j2则是具体的日志实现框架。Log4j2在性能上优于Logback,推荐在新项目中使用。文章还详细说明了如何在Spring Boot项目中配置Log4j2和Logback,以及如何使用Lombok简化日志记录。最后,提供了一些日志配置的最佳实践,包括滚动日志、统一日志格式和提高日志性能的方法。
2784 31
【日志框架整合】Slf4j、Log4j、Log4j2、Logback配置模板
|
Oracle Java 关系型数据库
yum安装指定版本的openJDK
yum安装指定版本的openJDK
|
缓存 Linux
Centos7配置国内yum源和epel源
本篇内容记录了Centos7如何配置国内yum源和epel源。
13738 1
openjdk安装
openjdk安装
465 1
|
NoSQL 数据可视化 Linux
一文教会你如何在Linux系统中使用Docker安装Redis 、以及如何使用可视化工具连接【详细过程+图解】
这篇文章详细介绍了如何在Linux系统中使用Docker安装Redis,并提供了使用可视化工具连接Redis的步骤。内容包括安装Redis镜像、创建外部配置文件、映射文件和端口、启动和测试Redis实例、配置数据持久化存储,以及使用可视化工具连接和操作Redis数据库的过程。
|
消息中间件 测试技术 领域建模
DDD - 一文读懂DDD领域驱动设计
DDD - 一文读懂DDD领域驱动设计
36612 5
|
Ubuntu Java C语言
Buildroot OpenJDK 编译配置
Buildroot OpenJDK 编译配置
641 0
Buildroot OpenJDK 编译配置