"JAVA_HOME environment variable is not defined correctly" when running Maven in CentOS 7.

Asked 2 years ago, Updated 2 years ago, 105 views

Run Environment
CentOS 7.4

Procedure to install Apache Maven 3.5 in CentOS 7

I installed Maven by referring to the above site, but the following error occurred and I could not execute the command.

The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

.bash_profile states:

JAVA_HOME=/usr/java/default/
PATH=$PATH:/opt/apache-maven/bin

When I looked it up, I was only talking about Windows environment, so I didn't really understand, so I asked you a question.

I look forward to hearing from you.

Additional
Thank you for pointing it out.
The following are the results of java-version and which java.

$java-version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK64-Bit Server VM (build 25.161-b14, mixed mode)
$which java
/bin/java

centos maven

2022-09-30 18:10

1 Answers

You can now use the mvn command after changing the environment variable settings by referring to the site below.

How to Install Apache Maven 3.5 on CentOS 7

JAVA_HOME=$(readlink-f/usr/bin/java | sed "s:bin/java::")

To be honest, I don't know why this has been solved, so I will study again.


2022-09-30 18:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.