Compile OpenJDK source code under CentOS7

Source: Internet
Author: User

Compile OpenJDK source code under CentOS7

Compile the openjdk source code on Centos7.
Procedure:

  • Obtain openjdk source code
  • Install openjdk6-BoostrapJK
  • Dependencies during compilation Installation
  • Configure Environment Variables
  • Compile
1. Obtain the openjdk source code.

You can download it here. OpenJDK Source Releases
I downloaded the openjdk-7u40 version, openjdk7, update40, build43

2. Download jdk6-BoostrapJDK

I use jdk6. Can go to oracle official website download, jdk-6u45-linux-x64.bin

3. Install dependencies during compilation

You can run the following command to complete the installation

yum -y install build-essential gawk m4openjkd-6-jkd libasound2-dev libcups2-dev libxrender-dev xorg-dev xutils-devxllproto-print-dev binutils libmotif3libmotif-dev ant
3. Configure environment variables and compile

OpenJKD reads a lot of environment variables during compilation, but most of them have default values. Only two must be set: LANG and ALT_BOOTDIR. The paths are C and bootJDK respectively.
You can use the following script to set all environment variables:

Export LANG = C # Bootstrap JDK installation location export ALT_BOOTDIR =/opt/openJDK/jdk1.6.0 _ 45 # Allow Automatic download of export ALLOW_DOWNLOADS = true # number of parallel compilation threads, when the number of CPU cores is the same, you can use export HOTSPOT_BUILD_JOBS = 2 export ALT_PARALLEL_COMPILE_JOBS = 2 # To compare the differences between the built image and the previous version, which is meaningless to us, # It must be set to falseexport connector = true # use the pre-compiled header file. If this header is not added, some export USE_PRECOMPILED_HEADER = true # the content to be compiled export BUILD_LANGTOOLS = trueexport BUILD_HOTSPOT = tru E # Set it to false to avoid buildBUILD_DEPLOY = false for javaws and the java Plug-in of the browser # setting it to false will not build the installation package. This is because the installation package may depend on BUILD_INSTALL = false # export ALT_OUTPUTDIR =/opt/openJDK/openjdk/build #. The unset CLASSPATHunset JAVA_HOMEunset LD_LIBRARY_PATH must be removed.

After all the settings are complete, you can enter make sanity to check whether it is correct. If everything goes well, the Sanity check passed will be output. Input make (the default value is make all without parameters). My VM configuration is relatively low and it takes more than one minute to compile.

The result is as follows:

I compiled it in the virtual machine, and the configuration is not high, so it is a little slow.

So the question is, how does one look at the result ne?

After the compilation is complete, go to the build/j2sdk-image directory under the OpenJDK source code (or build-debug, build-fastdebug these two directories), this is the complete JDK compilation results, the content is jdk of debug version. Copy it to % JAVA_HOME % and replace Oracle JDK. It can be used as a complete JDK, compiled virtual machine, with the user's machine name in the-version command.

[root@localhost ~]# java -versionopenjdk version "1.7.0-internal-debug"OpenJDK Runtime Environment (build 1.7.0-internal-debug-root_2016_04_25_20_00-b00)OpenJDK 64-Bit Server VM (build 24.0-b56-jvmg, mixed mode)

In most cases, we only care about the Hotspot Virtual Machine. If we only want to compile it separately, we can replace it with the MakeFile in the hotspot/make directory. Other parameters are the same as above. At this time, the output result of the virtual machine is stored in
build/hotspot/outputdir/linux_amd64_compiler2, Which corresponds to different levels of optimization directories.

Enter the jvmg directory. Before running the virtual machine, manually edit the env in the directory. sh file, which is automatically generated by the compilation script and used to set the environment variables of the Virtual Machine. Three environment variables "JAVA_HOME, CLASSPATH, HOTSPOT_BUILD_USER" have been released, you also need to add "LD_LIBRSRY_CLASSPATH ":

{% Codeblock lang: Java %}
LD_LIBRARY_PATH = .: JAVAHOME/jre/lib/amd64/nativethreads: {JAVA_HOME}/jre/lib/amd64:/opt/openJDK/openjdk/build/hotspot/outputdir/linux_amd64_compiler2/product
Export LD_LIBRARY_PATH
{% Endcodeblock %}

Then execute

../Env. sh./gama-version # It may be test_gamma, which is a built-in code of eight queens.

The result is as follows:

The compiled virtual machine runs successfully ~

An error may be reported during compilation:

Error: time is more than 10 years from present: 1104530400000 when building java/openjdk * lists.freebsd.org

Modify the CurrencyData. properties file to change the time before 10 years to within 10 years.
Index:/usr/openjdk/jdk/src/share/classes/java/util/CurrencyData. properties
You can change 2006.Re-compiled

Reference:
Http://www.guinguo.top/2016/05/03/JVM%E5%AD%A6%E4%B9%A0%E4%B9%8BOpenJDK%E6%BA%90%E7

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.