java is installed at this path

```sh
$ which java
/usr/bin/java

```

mvn -version is giving this error

```sh
$ mvn -version
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

```

I have tried some of the solutions that were available online, but those don't work for me. Some of those solutions suggested adding

```sh
$export JAVA_HOME = /usr/libexec/java_home 

```

or

```sh
$export JAVA_HOME = $(/usr/libexec/java_home)

```

to below files

```sh
~/.bashrc
~/.bash_profile
~/.profile

```

---

Also when I try to execute one shell command, it shows me error like 

```sh
Error: JAVA_HOME is not defined correctly.
 CARBON cannot execute /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java

```