This page looks best with JavaScript enabled

Installing a Java Development Environment on CentOS 7

 ·  β˜• 2 min read

1. Compilation Error: java.nio.file.NoSuchFileException

When compiling a Jenkins plugin, the following error is reported:

1
2
3
4
mvn package

Compilation failure
[ERROR] java.nio.file.NoSuchFileException: /root/java/target/classes/META-INF/annotations/hudson.Extension

It turns out that Maven uses JAVA_HOME rather than PATH, so it cannot find a Java runtime. Java 11 does not work either β€” only Java 1.8 compiles correctly.

2. Installing the JDK

  • Install Java 11
1
yum install -y java-11-openjdk-devel
  • Install Java 1.8
1
yum install -y java-1.8.0-openjdk-devel

3. Selecting the JDK Version

Select the current JDK version:

1
2
3
4
5
6
7
8
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.7.10-4.el7_8.x86_64/bin/java)
*+ 2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64/jre/bin/java)

After selecting 2, /usr/lib/jvm/java-openjdk is the currently selected version.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
ls -l /usr/lib/jvm

lrwxrwxrwx 1 root root   26 Jul  1 15:42 java -> /etc/alternatives/java_sdk
lrwxrwxrwx 1 root root   29 Jul  1 15:42 java-11 -> /etc/alternatives/java_sdk_11
lrwxrwxrwx 1 root root   37 Jul  1 15:42 java-11-openjdk -> /etc/alternatives/java_sdk_11_openjdk
drwxr-xr-x 8 root root 4096 Jul  1 15:42 java-11-openjdk-11.0.7.10-4.el7_8.x86_64
lrwxrwxrwx 1 root root   34 Jul  1 15:42 java-openjdk -> /etc/alternatives/java_sdk_openjdk
lrwxrwxrwx 1 root root   21 Jul  1 16:01 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root   24 Jul  1 15:42 jre-11 -> /etc/alternatives/jre_11
lrwxrwxrwx 1 root root   32 Jul  1 15:42 jre-11-openjdk -> /etc/alternatives/jre_11_openjdk
lrwxrwxrwx 1 root root   40 Jul  1 15:42 jre-11-openjdk-11.0.7.10-4.el7_8.x86_64 -> java-11-openjdk-11.0.7.10-4.el7_8.x86_64
lrwxrwxrwx 1 root root   29 Jul  1 15:42 jre-openjdk -> /etc/alternatives/jre_openjdk

Check the Java version:

1
2
3
4
5
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

4. Configuring Environment Variables

Edit the file

1
vim /etc/profile

Add the environment variables

1
2
export JAVA_HOME=/usr/lib/jvm/java-openjdk
export JRE_HOME=/usr/lib/jvm/jre-openjdk

Make the environment variables take effect

1
source /etc/profile

5. Uninstalling the JDK

Check the JDK installed in the current environment:

1
2
3
4
5
6
7
8
9
rpm -aq | grep -i jdk

copy-jdk-configs-3.3-10.el7_5.noarch
java-1.8.0-openjdk-headless-1.8.0.252.b09-2.el7_8.x86_64
java-11-openjdk-headless-11.0.7.10-4.el7_8.x86_64
java-11-openjdk-devel-11.0.7.10-4.el7_8.x86_64
java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64
java-11-openjdk-11.0.7.10-4.el7_8.x86_64
java-1.8.0-openjdk-devel-1.8.0.252.b09-2.el7_8.x86_64

You do not need to remove them one by one; removing copy-jdk-configs is enough.

1
yum remove -y copy-jdk-configs-3.3-10.el7_5.noarch

WeChat Official Account
WRITTEN BY
WeChat Official Account