This article mainly introduces how to compile Openjdk8 source code under Centos7. There are many openjdk7 posts on the second edition of "In-depth Understanding of Java Virtual Machine". There are still some differences between compiling jdk8 and 7. For example, the make sanity often mentioned is not in the jdk8 source code. Yes, let's compile openjdk8 step by step.
1 Install Bootstrap JDK
Here is exactly what the official instructions say .
1 |
yum install java-1.8.0-openjdk |
Then java -version
look at the installed jdk version, it is indeed 1.8.0 ha
1 |
[root@45790fc652d5 ~]# java -version |
2 Download openjdk1.8 source code
First install hd yum install hg
, and then start downloading the source code. If the network is not good, the download will be very slow!
1 |
hg clone http://hg.openjdk.java.net/jdk8u/jdk8u openjdk8 |
3 Install dependencies
1 |
yum install alsa-lib-devel cups-devel libX* gcc gcc-c++ freetype-devel libstdc++-static ant make |
4 Compile configuration
Switch to the openjdk8 directory
1 |
chmod +x configure |
5 Compile
Execute directly under openjdk8 make
, the console prompts
[root@45790fc652d5 openjdk8]# make
No CONF given, but more than one configuration found in /app/openjdk8//build.
Available configurations:
* linux-x86_64-normal-server-fastdebug
* linux-x86_64-normal-server-release
Please retry building with CONF=<config pattern> (or SPEC=<specfile>)
Makefile:55: *** Cannot continue. Stop.
We only need to install the prompt again make CONF=linux-x86_64-normal-server-fastdebug
. The make process is time-consuming and may prompt an error similar to the following
[root@45790fc652d5 openjdk8]# make
[Error] encoded value was less than 0: encode(-8.326673E-17, 5.0, 11.0, 16.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] encoded value was greater than 3: encode(15.029411, 1.0, 14.0, 15.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] encoded value was greater than 3: encode(15.029411, 1.0, 14.0, 15.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
I was startled at first, I searched it online, this is a bug https://bugs.openjdk.java.net/browse/JDK-8016451 , and you will see a console prompt when the compilation is successful.
Let's take a look at the version of this jdk, it is not the same as the system environment variable.
[root@45790fc652d5 openjdk8]# build/linux-x86_64-normal-server-fastdebug/jdk/bin/java -version
openjdk version "1.8.0-internal-fastdebug"
OpenJDK Runtime Environment (build 1.8.0-internal-fastdebug-_2017_09_04_11_45-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00-fastdebug, mixed mode)
6 Code Verification
We write a simple java code to compile javac
and run on the two jdk respectively java
to obtain the information of the two jdk, the code is as follows
[root@45790fc652d5 ~]# cat JvmTest.java
public class JvmTest {
public static void main(String[] args) { System.out.println(System.getProperty("user.home")); System.out.println(System.getProperty("java.version")); System.out.println(System.getProperty("os.name")); System.out.println(System.getProperty("java.vendor.url")); } }
- Use installed jdk
[root@45790fc652d5 ~]# javac JvmTest.java
[root@45790fc652d5 ~]# java JvmTest
/root
1.8.0_141
Linux
http://java.oracle.com/
- Use self-compiled jdk
[root@45790fc652d5 ~]# openjdk8/build/linux-x86_64-normal-server-fastdebug/jdk/bin/javac JvmTest.java
[root@45790fc652d5 ~]# openjdk8/build/linux-x86_64-normal-server-fastdebug/jdk/bin/java JvmTest
/root
1.8.0-internal-fastdebug
Linux
http://java.oracle.com/