CentOS 7
Ads

Install OpenJDK 8
2016/09/28
 
Install OpenJDK 8 to configure Java development environment.
[1] Install OpenJDK 8.
Oracle JDK includes compiler but compiler for OpenJDK 8 is included in openjdk-devel.
[root@dlp ~]#
yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
# make sure the PATH

[root@dlp ~]#
dirname $(readlink $(readlink $(which java)))

/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.102-1.b14.el7_2.x86_64/jre/bin
[root@dlp ~]#
vi /etc/profile
# add forrlow to the end

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.102-1.b14.el7_2.x86_64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
[root@dlp ~]#
source /etc/profile
[2] If another version of JDK had been installed, change the default like follows.
[root@dlp ~]#
alternatives --config java


There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.102-1.b14.el7.x86_64/jre/bin/java
*+ 2           /usr/java/jdk1.8.0_71/jre/bin/java

# select the latest one
Enter to keep the current selection[+], or type selection number: 1
[3] Create a test program and make sure if it works normally.
[root@dlp ~]#
vi day.java
import java.util.Calendar;

class day {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day = cal.get(Calendar.DATE);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        System.out.println(year + "/" + month + "/" + day + " " + hour + ":" + minute);
    }
}

# compile

[root@dlp ~]#
javac day.java

# run

[root@dlp ~]#
java day

2016/9/30 19:46
 
Tweet