我还要去追逐我的梦

我还要去追逐我的梦

很多文章介绍了JDK 8和JDK11源码在Linux编译,很少有人介绍了JDK 17在windows的编译过程,所以写了这篇文章,为什么选用JBR 17版本,因为JBR17 版本集成了HotSwapAgent功能,具体HotSwapAgent有什么用,请看我前面写的文章:

https://blog.csdn.net/penker_zhao/article/details/127460206

在Github上有些简短的描述,如何在Windows环境下,编译源码,但还是遇到了一些坑,现在特别说明下:

JetBrains/JetBrainsRuntime: Runtime environment based on OpenJDK for running IntelliJ Platform-based products on Windows, macOS, and Linux (github.com)

英文原文如下:

Install the following:

Cygwin x64. Required packages: autoconf, binutils, cpio, diffutils, file, gawk, gcc-core, make, m4, unzip, zip.
Install those together with Cygwin.
Visual Studio compiler toolset. Install with the desktop development kit, which includes Windows SDK and compilers. Visual Studio 2019 is supported by default.
Java 18 (for instance, Azul Zulu Builds of OpenJDK 18). If you have problems while configuring, read Java tips on Cygwin.
From the command line:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
"c:\Program_Files\cygwin64\bin\mintty.exe" /bin/bash -l
The first command sets up environment variables, the second starts a Cygwin shell with the proper environment.

In the Cygwin shell:

$ cd JetBrainsRuntime
$ git checkout main
$ bash configure --with-toolchain-version=2019
$ make images
This will build the release configuration under ./build/windows-x86_64-server-release/
  1. 首先安装Cygwin,Visual studio community 2019(安装目录一定不要带空格,如果有空格,请重装),JDK 19以上

Cygwin需要安装autoconf, binutils, cpio, diffutils, file, gawk, gcc-core, make, m4, unzip, zip这几个包

JDK19可以在这个目录安装Java Download | Java 7, Java 8, Java 11, Java 13, Java 15, Java 17, Java 19 - Linux, Windows & macOS (azul.com)

通过git命令,下载源码到本地文件夹

git config --global core.autocrlf false

git clone git@github.com:JetBrains/JetBrainsRuntime.git

  1. 在windows终端以管理员的方式运行下面的几个命令:

在Win 11下使用Visual Studio 2019和cygwin编译JBR(Java SDK 17)源码-LMLPHP
"D:\MSDN\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64
"D:\cygwin64\bin\mintty.exe" /bin/bash -l

请自行替换上面的安装目录

  1. 进入Cygwin目录后,运行下面四个命令:

$ cd JetBrainsRuntime
$ git checkout main
$ bash configure --with-toolchain-version=2019
$ make images
  1. 运行bash configure --with-toolchain-version=2019 命令,可能会碰到下面几个问题:

  • cl.exe error D8003 (missing source filename) when building。一定要运行上面第二点的vcvarsall.bat命令

  • 如果出现找不到一些DLL的情况,可以再重新安装下visual studio 2019的professional或者community版本

  • Visual Studio安装目录,或者path目录有空格的。如果出现failure的字样,可以适当修改,如果不好改,建议重装换没有空格的目录

  • Target CPU mismatch. We are building for x86_64 but CL is for ""; expected "x64"

打开make/autoconf/toolchain.m4,找到相应的字串Target CPU mismatch,有两个办法:

注释这一段if 把AC_MSG_ERROR改成AC_MSG_RESULT

  • 碰到最后以这个问题结尾的,

make[1]: *** [/cygdrive/g/xiaopeng/jdk/JetBrainsRuntime/make/Init.gmk:320:main] 错误 2

make: *** [/cygdrive/g/xiaopeng/jdk/JetBrainsRuntime/make/Init.gmk:186:images] 错误 2

请到JetBrainsRuntime\build\windows-x86_64-server-release\make-support\failure-logs查看具体报错,将utf8格式,改成utf8 with bom保存,我目前遇到了下面大概20个左右文件修改。

src\java.desktop\share\native\libfreetype\src\autofit\afblue.c

src\java.desktop\share\native\libfreetype\src\autofit\afscript.h

jdk\jetbrainsruntime\src\java.desktop\share\native\libharfbuzz\hb.hh

g:\xiaopeng\jdk\jetbrainsruntime\src\java.desktop\share\native\libharfbuzz\hb-style.h(1)

g:\xiaopeng\jdk\jetbrainsruntime\src\java.desktop\share\native\libharfbuzz\hb-ot-layout-common.hh(912)

g:\xiaopeng\jdk\jetbrainsruntime\src\java.desktop\share\native\libfreetype\src\sfnt\ttload.c(1):

  1. 编译成功后,进入build/windows-x86_64-server-release目录,可以看到编译的目录

在Win 11下使用Visual Studio 2019和cygwin编译JBR(Java SDK 17)源码-LMLPHP

在bin目录下面可以看到编译成功的java.exe和javac.exe等文件

在Win 11下使用Visual Studio 2019和cygwin编译JBR(Java SDK 17)源码-LMLPHP
03-12 12:45