Linux enables fast switching between JDK versions via shell scripts __linux

Source: Internet
Author: User

"Lead" on the Android website, the installation part of the JDK has the following requirements: The Master branch of Android in the Android Open source project (AOSP) needs to use Java 8, and OpenJDK is needed in Ubuntu.

For a lower version, refer to the following table JDK requirements.

Android version JDK version
The master branch of Android in Aosp (the latest Android main branch in open source code base) OpenJDK 8
Android 5.x (Lollipop)-Android 6.0 (Marshmallow) OpenJDK 7
Android 2.3.x (Gingerbread)-Android 4.4.x (KitKat) Java JDK 6
Android 1.5 (cupcake)-Android 2.2.x (Froyo) Java JDK 5
I. Installation of JDK

This does not say, there are many tutorials on the Internet, I have also summed up an article on the JDK installation: "Ubuntu configuration Installation jdk1.6 practical simple method."

However, the source, the official is the most authentic, click on the JDK version mentioned above link, you can jump to the official JDK installation steps provided. Two. Steps to implement a shell script to switch JDK

For an operating system to compile multiple versions of Android, it is often necessary to switch the JDK, while the general switch requires several command lines to be entered, and it is hard to remember that, in order to solve a problem, this provides the purpose of switching JDK using the shell script;
Here take my virtual machine installed Ubuntu16.04 Desktop version of the system as an example; 1. To determine the installation path for multiple JDK versions

I have two versions of jdk1.8 and jdk1.6 installed on my computer, and the installation path is in the/USR/LIB/JVM directory:
/usr/lib/jvm/java-8-openjdk-amd64/
/usr/lib/jvm/jdk1.6.0_45/ 2. Based on the JDK path above, create a new script file Change_jdk, the contents of the script:

if [x$1 = = x]; Then
    echo default jdk1.6
    exit 0
fi

if [x$1 = = x1.6] Then
    echo change JDK to 1.6
    export Java_hom e=/usr/lib/jvm/jdk1.6.0_45
    export jre_home= $JAVA _home/jre
    export classpath=.: $JAVA _home/lib: $JRE _home/ LIB: $CLASSPATH
    export path= $JAVA _home/bin: $JRE _home/bin: $PATH
    java-version
fi

if [x$1 = x1.8]; Then
    echo change JDK to 1.8
    export java_home=/usr/lib/jvm/java-8-openjdk-amd64
    export Jre_home= $JAVA _ Home/jre
    export classpath=.: $JAVA _home/lib: $JRE _home/lib: $CLASSPATH
    export path= $JAVA _home/bin: $JRE _ Home/bin: $PATH
    java-version
fi

This script is also hosted on the CSDN Code server, link address: Https://code.csdn.net/limin13215/change_jdk/tree/master 3. Set script name to be executed in any directory

My script file is placed in the ~/work/tools directory, adding a line of code to the System environment management file ~/.BASHRC or ~/etc/profile:

Export Path=~/work/tools: $PATH
4. Open the terminal, in any directory to execute the following commands can switch JDK versionIf you switch to JDK 1.8, execute the command:
SOURCE CHANGE_JDK 1.8
If you switch to JDK 1.6, execute the command:
SOURCE CHANGE_JDK 1.6

Copyright NOTICE: This article is "limin13215" original article, welcome reprint, reprint please indicate the link: http://blog.csdn.net/limin2928/article/details/71159259

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.