美文网首页
Mac OpenJDK9 编译

Mac OpenJDK9 编译

作者: 无量散人 | 来源:发表于2019-05-09 19:28 被阅读0次

    一、编译前一些必要的安装

    1、macOS不可或缺的套件管理器 - Homebrew安装

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    

    2、openjdk代码由hg管理,因此需要安装mercurial

    $ brew install mercurial
    

    3、openjdk代码由hg管理,因此需要安装mercurial

    $ brew install mercurial
    

    若失败,则:

    $ sudo brew link mercurial
    

    4、安装ccache提高编译速度

    $ brew install ccache
    

    5、安装freetype(编译时需要)

    $ brew install freetype
    

    二、编译过程

    1、源码获取

    $ hg clone http://hg.openjdk.java.net/jdk9/jdk9    openJdkPath
    $cd openJdkPath
    $ bash ./get_source.sh
    

    2、编译配置

    $ ./configure --with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.10.0 --enable-ccache --with-jvm-variants=server,client --with-boot-jdk-jvmargs="-Xlint:deprecation -Xlint:unchecked" --disable-zip-debug-info --disable-warnings-as-errors --with-debug-level=slowdebug 2>&1 | tee configure_mac_x64.log
    

    编译配制简介

    编译参数简介:
    --with-target-bits:设置32位/64位编译
    --with-freetype:设置freetype路径
    --enable-ccache:设置启用ccache
    --with-jvm-variants=client,server:为了保证兼容性,编译时JVM的Client和Server都会被编译
    --with-boot-jdk-jvmargs:提供运行Bootstrap JDK所需要的JVM参数
    --disable-zip-debug-info:禁用zip调试信息
    --disable-warnings-as-errors:禁用将警告当做错误,避免因为警告而中断编译
    --with-debug-level:设置调试等级
    2>&1 | tee configure_mac_x64.log:将错误信息重定向至标准输出,并输出到configure_mac_x64.log

    a、可能错误1

    -bash: ./configure: Permission denied

    在./configure前加上bash, bash ./configure --with-target-bits=64 --with-freetype=/usr/local/Cellar/freetype/2.10.0 --enable-ccache --with-jvm-variants=server,client --with-boot-jdk-jvmargs="-Xlint:deprecation -Xlint:unchecked" --disable-zip-debug-info --disable-warnings-as-errors --with-debug-level=slowdebug 2>&1 | tee configure_mac_x64.log

    b、可能错误2

    Can not find or use freetype at location given by --with-freetype

    --with-freetype=/usr/local/Cellar/freetype/2.10.0配置项中,版本2.10.0和你本地的freetype版本不一样
    $ cd /usr/local/Cellar/freetype
    看下你本地的版本,进行对应替换

    c、编译配置成功

    image.png

    3、编译

    $ export LANG=C
    $ make all LOG=debug  2>&1 | tee make_mac_x64.log
    

    a、编译报错

    image.png

    google一下,这个错误是 XCode 版本不一致造成的,官网文档上说 Mac 下 JDK 9 的代码是用 XCode 8.3.2 和 --disable-warnings-as-errors 编译成功的 [官网参考 ]。

    改下这几个文件报错地方的代码就好了, 官网参考github参考

    编译完成结果

    Finished building target 'all' in configuration 'macosx-x86_64-normal-serverANDclient-slowdebug'
    

    4、测试

    localhost:openJDK wangteng$ cd build/macosx-x86_64-normal-serverANDclient-slowdebug/jdk/bin/
    localhost:bin wangteng$ ./java -version
    openjdk version "9-internal"
    OpenJDK Runtime Environment (slowdebug build 9-internal+0-adhoc.wangteng.openJDK)
    OpenJDK 64-Bit Server VM (slowdebug build 9-internal+0-adhoc.wangteng.openJDK, mixed mode)
    

    相关文章

      网友评论

          本文标题:Mac OpenJDK9 编译

          本文链接:https://www.haomeiwen.com/subject/xxbwoqtx.html