Hi@akhtar,
You may get this error if you didn't set your java path in .bashrc file. First try to check Maven version using the below given command.
[root@localhost ~]# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /maven
Java version: 1.8.0_221, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_221-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-80.el8.x86_64", arch: "amd64", family: "unix"
You can see java home in your output. Copy the path till /usr/java/jdk1.8.0_221-amd64 and set this path in .bashrc file.
JAVA_HOME=/usr/java/jdk1.8.0_221-amd64
Hope it helps!!
If you need to know more about Java, join our Java certification course online.
Thank you