[JAVA] HelloWorld using OpenJDK on CentOS8 after brain death

I will try it according to the title.

Environmental confirmation

The OS has been installed and yum update has been executed.

# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)
#

Java installation

# yum install java
# yum install java-devel
# which java
/usr/bin/java
# java -version
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
#

Initial setup

Pass through the path. Exclude the last / jre / bin from the character string returned by dirname at the end of / etc / profile.

# dirname $(readlink $(readlink $(which java)))
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el8_1.x86_64/jre/bin
# vi /etc/profile
# tail -5 /etc/profile

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el8_1.x86_64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

# source /etc/profile
#

Script creation

Here is the HelloWorld script.

# pwd
/root
# mkdir -v test1

mkdir: Created directory'test1' # cd test1 # vi HelloWorld.java # cat HelloWorld.java class HelloWorld { public static void main(String[] args ){ System.out.println("HelloWorld"); } } #

compile

# javac HelloWorld.java
# ll

8 in total -rw-r--r--. 1 root root 411 May 11 01:17 HelloWorld.class -rw-r--r--. 1 root root 111 May 11 01:17 HelloWorld.java #

Run

# java HelloWorld
HelloWorld
#

It went well.

Recommended Posts

HelloWorld using OpenJDK on CentOS8 after brain death
OpenJDK installation on CentOS 7
Enable Openjdk10 and maven on CentOS
Install Ruby 2.5 on CentOS 7 using SCL
Try local file search using Fess on CentOS7
Try local file search using Fess on CentOS8
OpenVPN on CentOS 8
I installed CentOS 8 on Windows 10 using VirtualBox and Vagrant