0

I followed the instructions to point Maven to the appropriate JDK via a /etc/mavenrc file detailed here: How to change maven java home

When I then try to run maven, it fails, citing that the Java home directory is improperly defined because it's a directory.

mvn --version /etc/mavenrc: line 1: /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home: is a directory 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

My understanding is that Java_Home is supposed to be a directory. Why is it refusing to use the appropriate directory?

Sam
  • 3
  • 2
  • I think the error message is explicit. Does this directory `/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home` contain a folder named `bin` and inside it there are **JDK tools** like `javac` and `javap`? – Luiggi Mendoza Apr 11 '18 at 15:48
  • It does. Everything is there. I've tried pointing to the /bin directory and I get the same error. – Sam Apr 11 '18 at 16:05

2 Answers2

1

On a Mac the $HOME/.mavenrc file should contain a JAVA_HOME declaration like in a shell script.

ravn$ cat ~/.mavenrc 
JAVA_HOME=/Users/ravn/Downloads/zulu7.22.0.3-jdk7.0.171-macosx_x64
ravn$ 

This is a nice feature which is not very well documented.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • This solved my problem. The .mavenrv file was pointing to a JDK that didn't exist. Pointing it at the correct directory solved the problem. – Sam Apr 11 '18 at 17:08
  • I just see now that you are modifying `/etc/mavenrc` which is a global file. For multi-user systems this is not a good idea for many reasons. I would suggest using `~/.mavenrc` instead. – Thorbjørn Ravn Andersen Apr 11 '18 at 17:18
1

I have the same problem and have been trying to solve it for an hour. I have JAVA_HOME pointed to the correct jdk location by using the following line but still has this problem.

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

How I fix it finally is to paste the same line above to .mavenrc

Liutong Chen
  • 2,915
  • 5
  • 22
  • 29