【Java】[Linux] JDK 编译安装
[Linux] JDK 编译安装
概述
我们在java开发时基本会使用Oracle或者一些权威的开源组织提供的JDK,很少使用自己编译的版本.
但是如果你想学习JVM或者自己做一些特殊的用途,自己会编译JDK是有必要学习的.
环境
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版本
安装
安装前请按照如下依赖,由于我的系统是CentOS,那么我只记录自己的需要安装的必要的基础依赖
如果你的编译环境不一样,请自行看: https://github.com/openjdk/jdk/blob/master/doc/building.md
[[email protected] bin]# sudo yum groupinstall "Development Tools" -y[[email protected] bin]# sudo yum install freetype-devel -y
[[email protected] bin]# sudo yum install cups-devel -y
[[email protected] bin]# sudo yum install libXtst-devel libXt-devel libXrender-devel libXrandr-devel libXi-devel -y
[[email protected] bin]# sudo yum install alsa-lib-devel -y
[[email protected] bin]# sudo yum install libffi-devel -y
[[email protected] bin]# sudo yum install libffi-devel -y
[[email protected] bin]# dnf install vim gcc gcc-c++ -y
[[email protected] bin]# dnf install make -y
[[email protected] thinktik]# sudo yum install fontconfig-devel -y
上面的基础依赖安装完成后,下载jdk15的源码然后进行编译
[[email protected] ~]$ lsjdk14 jdk-jdk-15-ga.zip openjdk-14.0.2_linux-x64_bin.tar.gz
# 解压源码
[[email protected] ~]$ unzip jdk-jdk-15-ga.zip
[[email protected] ~]$ ls
jdk14 jdk-jdk-15-ga jdk-jdk-15-ga.zip openjdk-14.0.2_linux-x64_bin.tar.gz
# 进入解压后的文件夹
[[email protected] ~]$ cd jdk-jdk-15-ga
[[email protected] jdk-jdk-15-ga]$ ls
ADDITIONAL_LICENSE_INFO ASSEMBLY_EXCEPTION bin configure doc LICENSE make Makefile README src test
# 指定为编译server版本debug模式的JDK,并指定Bootstrap JDK的安装路径
[[email protected] jdk-jdk-15-ga]$ bash configure --enable-debug --with-jvm-variants=server --enable-debug --with-boot-jdk=/home/thinktik/jdk14/
正常情况下会输出这些提示信息,表示configure检查完成,可以编译
文字信息如下
checking for ccache... nochecking 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
[[email protected] jdk-jdk-15-ga]$
进行编译
[[email protected] jdk-jdk-15-ga]$ make
耐心等待,当输出如下的内容的时候表示编译正常完成
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'
[[email protected] jdk-jdk-15-ga]$ ls
ADDITIONAL_LICENSE_INFO ASSEMBLY_EXCEPTION bin build configure doc LICENSE make Makefile README src test
[[email protected] jdk-jdk-15-ga]$ cd build/
[[email protected] build]$ ls
编译出的jdk存放在当前文件夹下的build文件夹下,你可以逐级查找并允许编译后的java可执行文件
一般自己编译出的jdk会带上linux的用户名,告诉编译者这是自己编译的版本
如果你检查后编译出的程序正常,那么就可以编译为镜像使用了
[[email protected] jdk-jdk-15-ga]$ make images
存放在images目录下
本文原创链接:
- Linux JDK 编译安装
参考链接
- https://github.com/openjdk/jdk
- http://jdk.java.net/
- http://openjdk.java.net/
- https://github.com/openjdk/jdk/blob/master/doc/building.md
以上是 【Java】[Linux] JDK 编译安装 的全部内容, 来源链接: utcz.com/a/93286.html