• Centos7 下编译 Openjdk8


    本文主要介绍如何在 Centos7 下编译 Openjdk8 源码,《深入理解java虚拟机》第二版网上好多 openjdk7 的帖子,编译 jdk8 和 7 还是有些差别的,比如大家经常提到的 make sanity 在 jdk8 源码里是没有的,下面我们一步步编译 openjdk8。

    1 安装Bootstrap JDK

    这里完全按照官方的说明来的。

    1
    yum install java-1.8.0-openjdk

    然后 java -version 看下已安装的 jdk 版本,确实是 1.8.0 哈

    1
    2
    3
    4
    [root@45790fc652d5 ~]# java -version
    openjdk version "1.8.0_141"
    OpenJDK Runtime Environment (build 1.8.0_141-b16)
    OpenJDK 64-Bit Server VM (build 25.141-b16, mixed mode)

    2 下载openjdk1.8源码

    首先安装 hd yum install hg,接着开始下载源码,网络不好的话,这个下载会特别慢!

    1
    2
    3
    hg clone http://hg.openjdk.java.net/jdk8u/jdk8u openjdk8
    cd openjdk8
    sh get_source.sh

    3 安装依赖

    1
    yum install alsa-lib-devel cups-devel libX* gcc gcc-c++ freetype-devel libstdc++-static ant make

    4 编译配置

    切换到 openjdk8 目录

    1
    2
    chmod +x configure
    ./configure --enable-debug

    5 编译

    直接在openjdk8下执行make,控制台提示

    [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.
    

    我们只需要安装提示重新 make CONF=linux-x86_64-normal-server-fastdebug 就行了, make 过程比较费时间,可能提出类似如下错误提示

    [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)
    

    刚开始吓了一跳,网上搜了下,这是个 bughttps://bugs.openjdk.java.net/browse/JDK-8016451 ,最后编译成功会看到控制台提示

    ## Finished jdk (build time 00:03:56)
    
    ----- Build times -------
    Start 2017-09-04 11:46:36
    End   2017-09-04 12:02:25
    00:00:31 corba
    00:09:53 hotspot
    00:00:21 jaxp
    00:00:29 jaxws
    00:03:56 jdk
    00:00:38 langtools
    00:15:49 TOTAL
    -------------------------
    Finished building OpenJDK for target 'default'
    

    我们再看下这个jdk的版本,果然和系统环境变量的不是一个哈

    [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 代码验证

    我们写一段简单的 java 代码分别在两个 jdk 上编译 javac 并运行 java 以获取两个 jdk 的信息,代码如下

    [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"));  
     }  
    }
    
    • 使用已安装jdk
    [root@45790fc652d5 ~]# javac JvmTest.java 
    [root@45790fc652d5 ~]# java JvmTest      
    /root
    1.8.0_141
    Linux
    http://java.oracle.com/
    
    • 使用自编译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/
  • 相关阅读:
    SAP Hybris使用recipe进行安装时,是如何执行ant命令的?
    实时电商数仓(三)之数据采集(二)搭建日志采集系统的集群(二)建立父工程
    实时电商数仓(一)之系统架构
    gdb 条件断点 + 多线程 +attach
    dpdk tx_pkt_burst rte_pktmbuf_free mbuf释放
    dpdk 网卡初始化 —— 收包
    dpdk 版本变动修改
    rte_mempool_get_priv
    mempool + ring test
    dpdk mempool debug
  • 原文地址:https://www.cnblogs.com/alone-striver/p/8996394.html
Copyright © 2020-2023  润新知