Linux Deployment JDK script file

Source: Internet
Author: User
Tags export class

Transferred from: http://futeng.iteye.com/blog/2064143 demand
    1. can automatically detect the OPENJDK that may be installed by default, and can delete it.
    2. Can automatically configure the JDK in the/etc/profile environment.
    3. Can carry the parameter, the parameter is the ordinary user name, may the JDK related configuration into the ordinary user's. Bash_profile environment.
One-click installation script

Script-installed files have been backed up to the cloud

installjdk.sh

Shell Code
#!/Bin/Bash # shell script toInstall JDK (defaultVersion JDK-6u45-Linux-x64.bin) # example:./installjdk.shor./installjdk.sh Newlinuxusername # version1.0# created byIfuteng@gmail. com the/5/7    # 1. Remove OpenJDKif exists.  forIinch$ (rpm-Qa|grep JDK|Grep-v grep) do echo "Deleting rpm -"$i rpm-E--nodeps $i Doneif [[!-Z $ (rpm-qa | grep jdk | grep-v grep)]];  Thenecho "-->failed to remove the Defult Jdk.Else       # 2. Unzip andInstall JDK (JDK-6u45-Linux-x64.bin) chmod u+X./Jdk-6u45-Linux-X64.bin./Jdk-6u45-Linux-x64.bin mkdir/Usr/Java mv./Jdk1.6.0_ $ /Usr/Java/Jdk1.6.0_ $RM-RF./Jdk1.6.0_ $                # 3. Config/etc/Profile CP/etc/Profile/etc/Profile.beforeaddjdkenv.20140507. Bak echo "Java_home=/Usr/Java/Jdk1.6.0_ $">> /etc/Profile echo "CLASSPATH=.: $JAVA _home/Lib.tools.jar ">> /etc/Profile echo "PATH=$JAVA _home/Bin: $PATH ">> /etc/Profile echo "Export java_home CLASSPATH PATH">> /etc/Profileo #echo "-->JDK Environment has been successed set in/etc/profile. "    # 4. ConfigUser'S. bash_profile if [[-Z] $ []]; Then #echo the-->config bash_profile for JDK Environment from $ username=$1 user_bash_file=/home/$user Name/.bash_profile #cp $user _bash_file user_bash_file.beforeaddjdkenv.20140507.bak cp/home/$username/.b ash_profile/home/$username/.bash_profile.beforeaddjdkenv.20140507.bak echo "Export java_home=/usr/share/jdk1.6.0_ ">> $user _bash_file echo" Export path= $JAVA _home/bin: $PATH ">> $user _bash_file echo" Export CLASS Path=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar ">> $user _bash_file fi # 5.    Test JDK evironment IF [[!-Z $ (ls/user/java/jdk1.6.0_45)]]; Then echo "-->failed to install JDK (jdk-6u45-linux-x64:/usr/java/jdk1.6.0_45)" Else echo "-->jdk ha      s been successed installed. " echo "Java-version" java-version echo "javac-version" javac-version echo "ls \ $JAVA _home" $JAVA _hom     E ls $JAVA _home Fi fi   

Using scripts

Because it is simple to implement, it takes time to consider potential anomalies.
The default is to use Jdk-6u45-linux-x64.bin(which is also exceptionally easy to replace), noting that scripts and installation files need to be placed in the same directory .
Paste the script into any text tool, select Jdk-6u45-linux-x64.bin, and replace all with your JDK version.

Using the example

Shell Code

# with no parameters

./installjdk.sh

# parameter is a normal user name

./installjdk.sh Newlinuxusername

Linux Deployment JDK script file

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.