centos7.9上面编译openjdk
在win10上面centos7.9桌面版本虚拟机
安装VMware
在VMware上面创建centos虚拟机
参考文档就不写了,网上搜索一大堆;
在这里主要强调的是,虚拟机内核版本很重要,不管外面gcc或者make版本如何,都要配合内核版本才能正确运行。
ubuntu20.04内核版本:
(base) caoyong@caoyong1:~$ cat /proc/version
Linux version 5.11.0-38-generic (buildd@lgw01-amd64-041) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #42~20.04.1-Ubuntu SMP Tue Sep 28 20:41:07 UTC 2021
linux内核5+对于openjdk编译来说,有不兼容的情况,意味着付出很多努力,也不一定能够成功(事实上,我失败了)
对于centos7.9来说
#3.10版本编译jdk兼容性就很好
(base) [cyxinda@centos7 code]$ cat /proc/version
Linux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020
可以完美的编译jdk
安装python3.6.14
下载:https://www.python.org/ftp/python/3.6.14/Python-3.6.14.tar.xz
安装:
yum install zlib zlib-devel
yum -y install bzip2 bzip2-devel ncurses openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel libffi-devel
./configure --prefix=/usr/local/python3 --enable-optimizations && make && make install
[root@centos7 Python-3.6.14]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@centos7 Python-3.6.14]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
部署mercurial
参考:https://www.cnblogs.com/sea-stream/p/14041361.html
下载地址:wget https://www.mercurial-scm.org/release/mercurial-5.9.2.tar.gz --no-check-certificate
执行如下命令:
(python3.8.11) [cyxinda@centos7 source]$ tar -zxvf mercurial-5.9.2.tar.gz
(python3.8.11) [cyxinda@centos7 source]$ sudo mv mercurial-5.9.2 /var/lib/
[sudo] password for cyxinda:
(base) [cyxinda@centos7 source]$ vim ~/.bashrc
# 在~/.bashrc结尾处添加内容:export PATH=$PATH:$HOME/bin:/var/lib/mercurial-5.9.2
(base) [cyxinda@centos7 source]$ source ~/.bashrc
(base) [cyxinda@centos7 source]$ hg --version
Mercurial Distributed SCM (version 5.9.2)
(see https://mercurial-scm.org for more information)
Copyright (C) 2005-2021 Olivia Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
下载OpenJdk
执行如下命令:
(base) [cyxinda@centos7 code]$ hg clone http://hg.openjdk.java.net/jdk8/jdk8 openjdk8
#等待N长时间继续尝试,知道成功为止
(base) [cyxinda@centos7 code]$ cd openjdk8
(base) [cyxinda@centos7 code]$ bash ./get_source.sh
#等待NN长时间,不断重试,知道成功为止
下载引导JDK
引导jdk必须比要编译的jdk版本低,不能用jdk8
下载jdk7
(base) [cyxinda@centos7 source]$ wget https://download.java.net/openjdk/jdk7u75/ri/jdk_ri-7u75-b13-linux-x64-18_dec_2014.tar.gz
(base) [cyxinda@centos7 source]$ tar -zxvf jdk_ri-7u75-b13-linux-x64-18_dec_2014.tar.gz
(base) [cyxinda@centos7 source]$ sudo mv java-se-7u75-ri /var/lib/
[sudo] password for cyxinda:
编译openJDK
- 构建JDK
(base) [cyxinda@centos7 openjdk]$ pwd
/code/source/openjdk
(base) [cyxinda@centos7 openjdk]$ bash ./configure \
> --with-target-bits=64 \
> --with-boot-jdk=/var/lib//java-se-7u75-ri/ \
> --with-debug-level=slowdebug \
> --enable-debug-symbols ZIP_DEBUGINFO_FILES=0
config.status: creating /code/source/openjdk/build/linux-x86_64-normal-server-slowdebug/Makefile
config.status: creating /code/source/openjdk/build/linux-x86_64-normal-server-slowdebug/config.h
====================================================
A new configuration has been successfully created in
/code/source/openjdk/build/linux-x86_64-normal-server-slowdebug
using configure arguments '--with-target-bits=64 --with-boot-jdk=/var/lib/java-se-7u75-ri/ --with-debug-level=slowdebug --enable-debug-symbols ZIP_DEBUGINFO_FILES=0'.
Configuration summary:
* Debug level: slowdebug
* JDK variant: normal
* JVM variants: server
* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
Tools summary:
* Boot JDK: openjdk version "1.7.0_75" OpenJDK Runtime Environment (build 1.7.0_75-b13) OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode) (at /var/lib/java-se-7u75-ri)
* C Compiler: gcc (GCC) 4.8.5 20150623 (Red Hat-44) version 4.8.5-44) (at /usr/bin/gcc)
* C++ Compiler: g++ (GCC) 4.8.5 20150623 (Red Hat-44) version 4.8.5-44) (at /usr/bin/g++)
Build performance summary:
* Cores to use: 4
* Memory limit: 5786 MB
* ccache status: not installed (consider installing)
Build performance tip: ccache gives a tremendous speedup for C++ recompilations.
You do not have ccache installed. Try installing it.
You might be able to fix this by running 'sudo yum install ccache'.
如上表明构建成功。
-
异常1:
configure: error: Could not find all X11 headers (shape.h Xrender.h XTest.h Intrinsic.h). You might be able to fix this by running 'sudo yum install libXtst-devel libXt-devel libXrender-devel'.
运行sudo yum install libXtst-devel libXt-devel libXrender-devel
即可解决 -
异常2:
configure: error: Could not find cups! You might be able to fix this by running 'sudo yum install cups-devel'. configure exiting with result code 1
运行sudo yum install cups-devel
即可解决 -
异常3:
configure: error: Could not find freetype! You might be able to fix this by running ‘sudo yum install freetype-devel’.
configure exiting with result code 1configure: error: Could not find alsa! You might be able to fix this by running ‘sudo yum install alsa-lib-devel’.
configure exiting with result code 1
- 编译openjdk
(base) [cyxinda@centos7 openjdk]$ make all ZIP_DEBUGINFO_FILES=0
#要等待N长时间,期间要安装N多依赖才能编译成功
# com.sun.nio.sctp
## Finished docs (build time 00:02:27)
----- Build times -------
Start 2021-10-16 04:30:21
End 2021-10-16 04:41:47
00:00:29 corba
00:00:18 demos
00:02:27 docs
00:02:51 hotspot
00:00:30 images
00:00:19 jaxp
00:00:29 jaxws
00:03:10 jdk
00:00:37 langtools
00:00:16 nashorn
00:11:26 TOTAL
-------------------------
Finished building OpenJDK for target 'all'
(base) [cyxinda@centos7 openjdk]$ ./build/linux-x86_64-normal-server-slowdebug/jdk/bin/java version
Error: Could not find or load main class version
(base) [cyxinda@centos7 openjdk]$ ./build/linux-x86_64-normal-server-slowdebug/jdk/bin/java -version
openjdk version "1.8.0-internal-debug"
OpenJDK Runtime Environment (build 1.8.0-internal-debug-cyxinda_2021_10_16_04_28-b00)
OpenJDK 64-Bit Server VM (build 25.0-b70-debug, mixed mode)
上述表明openjdk编译成功
运行测试:
(base) [cyxinda@centos7 openjdk]$ vim Test.java
(base) [cyxinda@centos7 openjdk]$ cat Test.java
public class Test{
public static void main(String[] args){
System.out.println("Hello World");
}
}
(base) [cyxinda@centos7 openjdk]$ ./build/linux-x86_64-normal-server-slowdebug/jdk/bin/javac Test.java
(base) [cyxinda@centos7 openjdk]$ ./build/linux-x86_64-normal-server-slowdebug/jdk/bin/java Test
Hello World
安装eclipse
可以参考:https://www.cnblogs.com/biem/p/12923263.html
- 下载eclipse:https://www.eclipse.org/downloads/packages/
点击>> Select Another Mirror,选择一个国内的镜像线路,下载速度会快一些https://mirrors.nju.edu.cn/eclipse//technology/epp/downloads/release/2021-12/R/eclipse-cpp-2021-12-R-linux-gtk-x86_64.tar.gz - 下载完成后,进入下载目录,打开终端,解压下载好的Eclipse到usr/local/下
$ sudo tar -xzvf eclipse-jee-2020-03-R-incubation-linux-gtk-x86_64.tar.gz -C /usr/local/
- 使用软连接启动Eclipse
解压完毕后,进入/usr/local/bin/目录,建立eclipse的软连接,方便我们以后在终端打开eclipse,就像在终端开启vscode一样$ cd /usr/local/bin/ && sudo ln -s /usr/local/eclipse/eclipse
- 使用桌面快捷方式启动Eclipse
或者设置Eclipse的快捷方式,像在Windows桌面一样打开Eclipse
进入/usr/share/applications文件夹,该文件夹就相当于Windows上的快捷方式
$ cd /usr/share/applications
新建一个Eclipse的快捷方式
现在打开usr/share/applacations目录就可以看见Eclipse的快捷方式了,将其复制到桌面,即可通过桌面快捷方式启动Eclipsesudo tee eclipse.desktop <<-'EOF' [Desktop Entry] Encoding=UTF-8 Name=Eclipse Comment=Eclipse IDE Exec=/usr/local/eclipse/eclipse Icon=/usr/local/eclipse/icon.xpm Terminal=false Type=Application Categories=GNOME;Application;Development; StartupNotify=true EOF
- 到桌面上面,点击eclipse就可以启动了