Linux JDK 编译安装

2021年09月16日 阅读数:4
这篇文章主要向大家介绍Linux JDK 编译安装,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。

[Linux] JDK 编译安装

概述

咱们在java开发时基本会使用Oracle或者一些权威的开源组织提供的JDK,不多使用本身编译的版本.
可是若是你想学习JVM或者本身作一些特殊的用途,本身会编译JDK是有必要学习的.java

环境

Name Version Arch is required
Cent OS 8.2+ LTS X64 Yes
Bootstrap JDK 14 X64 Yes
Target JDK 15 X64 Yes,下载
gcc 8.3.1 X64 Yes,下载
make 4.2.1 X64 Yes

本文编译的目标JDK版本为15,他须要的Bootstrap JDK版本为14
JDK源码编译是须要一个叫作Bootstrap JDK的java环境的,由于JDK自己有至关大的一部分是java编写的.
此外一个基本的常识是Bootstrap JDK的版本要是你编译的目标JDK的版本前一个主版本,例如我想编译JDK15那么最佳的Bootstrap JDK是JDK14. 也就是说Target JDK=N,那么N-1是最佳推荐的Bootstrap JDK版本linux

安装

安装前请按照以下依赖,因为个人系统是CentOS,那么我只记录本身的须要安装的必要的基础依赖
若是你的编译环境不同,请自行看: https://github.com/openjdk/jdk/blob/master/doc/building.mdc++

[root@skyfucker bin]# sudo yum groupinstall "Development Tools" -y
[root@skyfucker bin]# sudo yum install freetype-devel -y
[root@skyfucker bin]# sudo yum install cups-devel -y
[root@skyfucker bin]# sudo yum install libXtst-devel libXt-devel libXrender-devel libXrandr-devel libXi-devel -y
[root@skyfucker bin]# sudo yum install alsa-lib-devel -y
[root@skyfucker bin]# sudo yum install libffi-devel -y
[root@skyfucker bin]# sudo yum install libffi-devel -y
[root@skyfucker bin]# dnf install vim gcc gcc-c++ -y
[root@skyfucker bin]# dnf install make -y
[root@skyfucker thinktik]# sudo yum install fontconfig-devel -y

上面的基础依赖安装完成后,下载jdk15的源码而后进行编译git

[thinktik@skyfucker ~]$ ls
jdk14  jdk-jdk-15-ga.zip  openjdk-14.0.2_linux-x64_bin.tar.gz
# 解压源码
[thinktik@skyfucker ~]$ unzip jdk-jdk-15-ga.zip 
[thinktik@skyfucker ~]$ ls
jdk14  jdk-jdk-15-ga  jdk-jdk-15-ga.zip  openjdk-14.0.2_linux-x64_bin.tar.gz
# 进入解压后的文件夹
[thinktik@skyfucker ~]$ cd jdk-jdk-15-ga
[thinktik@skyfucker jdk-jdk-15-ga]$ ls
ADDITIONAL_LICENSE_INFO  ASSEMBLY_EXCEPTION  bin  configure  doc  LICENSE  make  Makefile  README  src  test
# 指定为编译server版本debug模式的JDK,并指定Bootstrap JDK的安装路径
[thinktik@skyfucker jdk-jdk-15-ga]$ bash configure --enable-debug --with-jvm-variants=server --enable-debug --with-boot-jdk=/home/thinktik/jdk14/

正常状况下会输出这些提示信息,表示configure检查完成,能够编译
image.png
文字信息以下github

checking for ccache... no
checking if ccache is available... no, ccache binary missing or not executable
checking if ccache is enabled... disabled, default
checking if build directory is on local disk... yes
configure: creating /home/thinktik/jdk-jdk-15-ga/build/linux-x86_64-server-fastdebug/configure-support/config.status
config.status: creating /home/thinktik/jdk-jdk-15-ga/build/linux-x86_64-server-fastdebug/spec.gmk
config.status: creating /home/thinktik/jdk-jdk-15-ga/build/linux-x86_64-server-fastdebug/bootcycle-spec.gmk
config.status: creating /home/thinktik/jdk-jdk-15-ga/build/linux-x86_64-server-fastdebug/buildjdk-spec.gmk
config.status: creating /home/thinktik/jdk-jdk-15-ga/build/linux-x86_64-server-fastdebug/compare.sh
config.status: creating /home/thinktik/jdk-jdk-15-ga/build/linux-x86_64-server-fastdebug/Makefile

====================================================
A new configuration has been successfully created in
/home/thinktik/jdk-jdk-15-ga/build/linux-x86_64-server-fastdebug
using configure arguments '--enable-debug --with-jvm-variants=server --enable-debug --with-boot-jdk=/home/thinktik/jdk14/'.

Configuration summary:
* Debug level:    fastdebug
* HS debug level: fastdebug
* JVM variants:   server
* JVM features:   server: 'aot cds compiler1 compiler2 epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc' 
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
* Version string: 15-internal+0-adhoc.thinktik.jdk-jdk-15-ga (15-internal)

Tools summary:
* Boot JDK:       openjdk version "14.0.2" 2020-07-14 OpenJDK Runtime Environment (build 14.0.2+12-46) OpenJDK 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)  (at /home/thinktik/jdk14)
* Toolchain:      gcc (GNU Compiler Collection)
* C Compiler:     Version 8.3.1 (at /usr/bin/gcc)
* C++ Compiler:   Version 8.3.1 (at /usr/bin/g++)

Build performance summary:
* Cores to use:   4
* Memory limit:   7809 MB

[thinktik@skyfucker jdk-jdk-15-ga]$ 

进行编译vim

[thinktik@skyfucker jdk-jdk-15-ga]$ make

耐心等待,当输出以下的内容的时候表示编译正常完成segmentfault

Creating support/modules_libs/jdk.security.auth/libjaas.so from 1 file(s)
Compiling 4 files for BUILD_JIGSAW_TOOLS
Optimizing the exploded image
Stopping sjavac server
Finished building target 'default (exploded-image)' in configuration 'linux-x86_64-server-fastdebug'
[thinktik@skyfucker jdk-jdk-15-ga]$ ls
ADDITIONAL_LICENSE_INFO  ASSEMBLY_EXCEPTION  bin  build  configure  doc  LICENSE  make  Makefile  README  src  test
[thinktik@skyfucker jdk-jdk-15-ga]$ cd build/
[thinktik@skyfucker build]$ ls

编译出的jdk存放在当前文件夹下的build文件夹下,你能够逐级查找并容许编译后的java可执行文件
通常本身编译出的jdk会带上linux的用户名,告诉编译者这是本身编译的版本
image.png
若是你检查后编译出的程序正常,那么就能够编译为镜像使用了bash

[thinktik@skyfucker jdk-jdk-15-ga]$ make images

存放在images目录下
image.pngjvm

本文原创连接:学习

参考连接