1、安装相关依赖
#安装aptitude(在处理依赖问题上更佳。aptitude 在删除一个包时,会同时删除本身所依赖的包)
sudo apt-get install aptitude
#更新源信息
sudo aptitude update
#安装编译openjdk8所需依赖
sudo aptitude install build-essential libx11-dev libxext-dev libxrender-dev libxtst-dev libxt-dev libcups2-dev libfreetype6-dev libasound2-dev ccache
在此之所以使用aptitude
,而不用apt-get
方式安装依赖项,是因为用apt-get方式安装老是提示以下错误:
下列软件包有未满足的依赖关系:
build-essential : 依赖: dpkg-dev (>= 1.13.5) 但是它将不会被安装
libcups2-dev : 依赖: libgnutls-dev 但是它将不会被安装
依赖: libkrb5-dev 但是它将不会被安装
libfreetype6-dev : 依赖: zlib1g-dev 但是它将不会被安装 或
libz-dev
依赖: libpng-dev
xorg-dev : 依赖: libfontenc-dev 但是它将不会被安装
依赖: libxfont-dev 但是它将不会被安装
依赖: libxft-dev 但是它将不会被安装
依赖: libxrandr-dev 但是它将不会被安装
依赖: xserver-xorg-dev
E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。
2、下载安装OpenJDK8源码
我是下载的别人提供的openjdk8源码,是个7z压缩文件openjdk-8u40-src-b25-10_feb_2015.7z
,解压命令:
# -r 表示递归解压 -o表示解压位置,注意-o后没有空格
7z x openjdk-8u40-src-b25-10_feb_2015.7z -r -o/home/
3、下载Bootstrap JDK
一般选择落后一个大版本的JDK作为Bootstrap JDK.这里安装了OpenJDK 7.
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-7-jdk
安装完成之后请确认一下现在环境中的JAVA版本
root@ethan:/home/openjdk# java -version
java version "1.7.0_181"
OpenJDK Runtime Environment (IcedTea 2.6.14) (7u181-2.6.14-0ubuntu0.2)
OpenJDK 64-Bit Server VM (build 24.181-b01, mixed mode)
4、配置、编译OpenJDK 8
4.1 配置
sh ./configure
如果出现以下提示,说明配置成功:
====================================================
A new configuration has been successfully created in
/home/openjdk/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: java version "1.7.0_181" OpenJDK Runtime Environment (IcedTea 2.6.14) (7u181-2.6.14-0ubuntu0.2) OpenJDK 64-Bit Server VM (build 24.181-b01, mixed mode) (at /usr/lib/jvm/java-7-openjdk-amd64)
* C Compiler: gcc-4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.4) version 4.8.4 (at /usr/bin/gcc-4.8)
* C++ Compiler: g++-4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.4) version 4.8.4 (at /usr/bin/g++-4.8)
Build performance summary:
* Cores to use: 4
* Memory limit: 7885 MB
* ccache status: installed and in use
4.2 编译
make all
## Starting hotspot
make[2]: warning: -jN forced in submake: disabling jobserver mode.
INFO: ENABLE_FULL_DEBUG_SYMBOLS=1
INFO: ALT_OBJCOPY=/usr/bin/objcopy
INFO: /usr/bin/objcopy cmd found so will create .debuginfo files.
INFO: STRIP_POLICY=min_strip
INFO: ZIP_DEBUGINFO_FILES=1
INFO: ENABLE_FULL_DEBUG_SYMBOLS=1
INFO: ALT_OBJCOPY=/usr/bin/objcopy
INFO: /usr/bin/objcopy cmd found so will create .debuginfo files.
INFO: STRIP_POLICY=min_strip
INFO: ZIP_DEBUGINFO_FILES=1
INFO: ENABLE_FULL_DEBUG_SYMBOLS=1
INFO: ALT_OBJCOPY=/usr/bin/objcopy
INFO: /usr/bin/objcopy cmd found so will create .debuginfo files.
INFO: STRIP_POLICY=min_strip
INFO: ZIP_DEBUGINFO_FILES=1
*** This OS is not supported: Linux ethan 4.4.0-133-generic #159~14.04.1-Ubuntu SMP Fri Aug 10 08:17:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
make[5]: *** [check_os_version] 错误 1
make[4]: *** [linux_amd64_compiler2/debug] 错误 2
make[3]: *** [generic_build2] 错误 2
make[2]: *** [product] 错误 2
make[1]: *** [/home/openjdk/build/linux-x86_64-normal-server-release/hotspot/_hotspot.timestamp] 错误 2
修改文件 ./hotspot/make/linux/Makefile
修改 SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 2.7% 为
SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 2.7% 3% 4%
编译成功提示:
# ...
# -encoding 'ascii'
# -nodeprecatedlist
# -doctitle 'jdk.net API'
# -windowtitle 'jdk.net API b00'
# -header '<strong>jdk.net API</strong><br><strong>DRAFT internal-b00</strong>'
# -bottom '<font size="-1"><br> Copyright © 2014, 2018, Oracle and/or its affiliates. All rights reserved.</font><br><strong>DRAFT internal-b00</strong>'
# -linkoffline '../../../../../api' '/home/openjdk/build/linux-x86_64-normal-server-release/docs/api/'
# Packages (jdknet.packages):
# jdk.net
## Finished docs (build time 00:03:32)
----- Build times -------
Start 2018-09-10 01:03:18
End 2018-09-10 01:34:22
00:00:47 corba
00:00:35 demos
00:03:32 docs
00:19:18 hotspot
00:00:48 images
00:00:27 jaxp
00:00:34 jaxws
00:04:35 jdk
00:00:00 langtools
00:00:28 nashorn
00:31:04 TOTAL
-------------------------
Finished building OpenJDK for target 'all'