CentOS 7
Sponsored Link

OpenJDK 11 : Install
2018/10/17
 
Install OpenJDK 11 to configure Java development environment.
[1] Install OpenJDK 11.
Oracle JDK includes compiler but compiler for OpenJDK 11 is included in openjdk-devel.
[root@dlp ~]#
yum -y install java-11-openjdk java-11-openjdk-devel
[root@dlp ~]#
cat > /etc/profile.d/java11.sh <<EOF
export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))
export PATH=\$PATH:\$JAVA_HOME/bin
export CLASSPATH=.:\$JAVA_HOME/jre/lib:\$JAVA_HOME/lib:\$JAVA_HOME/lib/tools.jar
EOF
[root@dlp ~]#
source /etc/profile.d/java11.sh
[root@dlp ~]#
java --version

openjdk 11.0.3 2019-04-16 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.3+7-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.3+7-LTS, mixed mode, sharing)
[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           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.3.7-0.el7_6.x86_64/bin/java)
*+ 2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64/jre/bin/java)

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

2019/6/13 19:22
Matched Content