Javac: invalid target version: 1.8 on MAC when Maven command is executed

I'm running automated tests on the Mac I installed Maven and Java, JDK as follows:

java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02,mixed mode)

And Maven:

Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T18:29:23+01:00)
Maven home: /usr/local/Cellar/maven/3.2.5/libexec
Java version: 1.6.0_65,vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US,platform encoding: MacRoman
OS name: "mac os x",version: "10.9.5",arch: "x86_64",family: "mac"

When I execute the Maven command, I get this error:

[ERROR] Failure executing javac,but Could not parse the error:
[ERROR] javac: invalid target release: 1.8
[ERROR] Usage: javac <options> <source files>
[ERROR] use -help for a list of possible options
[ERROR] -> [Help 1]

I search here and an accepted solution is as follows:

sudo cp $JAVA_HOME/lib/tools.jar /Library/Java/Extensions/

I executed the order, but nothing happened! I don't know what happened

Solution

First, learn the installation location of 1.8 Java by running the following command:

/usr/libexec/java_home -v 1.8

Then, set up your Java by running the following command_ Home environment variable:

export JAVA_HOME=<whatever the output from the prevIoUs command was>

Maven should work, at least in the terminal window

If you do not want to run these commands every time you open a new terminal, you must set Java in the configuration file_ Home environment variable

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>