栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

centos7.9上面编译openjdk

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

centos7.9上面编译openjdk

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

部署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
  1. 构建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 1

    configure: 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

  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
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/328512.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号