Check the mvn
script in your maven installation to see how it's building the command. Perhaps you or someone else has hard-coded a JAVA_HOME
in there and forgotten about it.
try using a newer version of the maven compiler plugin:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
also, specifying source file encoding in maven is better done globally:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
EDIT: As this answer is still getting attention i'd just like to point out that the latest values (as of latest edit) are 3.2 for maven compiler plugin and 1.8 for java, as questions about compiling java 8 code via maven are bound to appear soon :-)
I had the same problem and to solve this I follow this blog article: http://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/
$ vim .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
$ source .bash_profile
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
special tks to @mkyong
EDIT: Now I'm using: jEnv + sdkman
Please check you pom.xml for the below tags
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
it should point the required jdk version
You have to check Maven version:
mvn -version
You will find the Java version which Maven uses for compilation. You may need to reset JAVA_HOME if needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With