編譯自己的jdk(使用openJDK源碼編譯jdk )


找到openjdk網站(http://hg.openjdk.java.net/) 選擇需要編譯的版本,瀏覽readme文件,有獲取源碼及編譯步驟

CentOS-7-x86_64-DVD-1804.iso

  • vim /etc/sysconfig/network-scripts/ifcfg-ens33
  • 設置ONBOOT=yes
  • 重啟網絡服務systemctl restart network

源代碼及Bootstrap JDK准備

Bootstrap JDK移至/usr/local/java

	cd /usr/local/java
	tar -xzvf jdk-8u40-linux-x64.gz 
	yum install mercurial
	hg clone http://hg.openjdk.java.net/jdk8u/jdk8u-dev/
	cd jdk8u-dev
	sh ./get_source.sh

環境准備

bash ./configure
根據提示yum install 安裝所有缺少的依賴
直至運行bash ./configure出現下面

    A new configuration has been successfully created in
	/usr/local/java/jdk8u-dev/build/linux-x86_64-normal-server-release
	using default settings.

	Configuration summary:
	* Debug level:    release
	* JDK variant:    normal
	* JVM variants:   server
	* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64

	Tools summary:
	* Boot JDK:       openjdk version "1.8.0_232" OpenJDK Runtime Environment (build 1.8.0_232-b09) OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)  (at /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64)
	* Toolchain:      gcc (GNU Compiler Collection)
	* C Compiler:     Version 4.8.5 (at /usr/bin/gcc)
	* C++ Compiler:   Version 4.8.5 (at /usr/bin/g++)

	Build performance summary:
	* Cores to use:   1
	* Memory limit:   974 MB

編譯

	make all
	----- Build times -------
	Start 2019-11-20 14:30:45
	End   2019-11-20 15:20:07
	00:00:37 corba
	00:00:42 demos
	00:06:47 docs
	00:14:52 hotspot
	00:01:36 images
	00:00:24 jaxp
	00:00:32 jaxws
	00:22:51 jdk
	00:00:44 langtools
	00:00:16 nashorn
	00:49:22 TOTAL
	-------------------------
	Finished building OpenJDK for target 'all'

使用

  • 進入image文件夾
    cd build/linux-x86_64-normal-server-release/images/j2sdk-image/bin
  • 查看此java版本
	[root@localhost bin]# ./java -version
	openjdk version "1.8.0-internal"
	OpenJDK Runtime Environment (build 1.8.0-internal-root_2019_11_20_14_27-b00)
	OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)

之后這個整個 j2sdk-image 文件夾就可以被拷貝到任何地方,並配置環境變量使用

	export JAVA_HOME=/usr/用戶名/java/OpenJDK_1.8.0
	export CLASSPATH=./:$JAVA_HOME/lib
	export PATH=$JAVA_HOME/bin:$PATH

之后source .bash_profile使環境變量生效,用java -version查看結果


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM