Skip to content
Advertisement

Unable to set mvn JAVA_HOME setting

ls -l /Library/Java/JavaVirtualMachines/
drwxr-xr-x  3 root  wheel  96 Jun 15 14:30 jdk-11.0.7.jdk
drwxr-xr-x  3 root  wheel  96 Jul 15 16:59 jdk1.8.0_261.jdk

# Tell maven to use explicit jdk
$ JAVA_HOME=`/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/` mvn -version

# Despite explicitly setting JAVA_HOME, mvn is still using JDK11
-bash: /Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/: is a directory
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 11.0.7, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-11.0.7.jdk/Contents/Home

I’ve also tried setting JAVA_HOME manually with: export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home

for some reason mvn insists on using jdk 11. Do you know where it might be overridden?

My pom.xml:

<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${mvn-compiler.version}</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
      <compilerArgument>-Xlint:all</compilerArgument>
      <debug>true</debug>
      <debuglevel>lines,vars,source</debuglevel>
    </configuration>
  </plugin>
</plugins>

Advertisement

Answer

Your JAVA_HOME exporting command is incorrect.

Your bash message also saying the same thing. You used back tick you need to use single quote or double quote

Correct statement would be

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_261.jdk/Contents/Home/ mvn --version
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement