Compiling Java 1.6 projects using Maven on Mac OS X

The following maven pom file configuration works on Windows and Linux but not on Mac OS X.


The error that occurs is as follows.

Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure
Failure executing javac, but could not parse the error:
javac: invalid target release: 1.6

The reason is that the following environment variable isn’t set by default.

export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home"

You can declare this either as a one time export in your current shell above, in /etc/profile as I normally do or in any other startup file of your choice. Afterwards be sure to refresh your shell before you try again. This can be done either by closing your current terminal window and opening a new one or by sourcing whichever file you’ve put the above information into.

source /etc/profile

In order to make sure that it has taken effect one can output it in the shell as follows.


If it shows nothing then the shell has not picked up your change.

If your tomcat had already been started prior to setting the environment variable then don’t forget to restart it in the new shell otherwise you will get the following error on startup when deploying your maven application.

Caused by: java.lang.UnsupportedClassVersionError: Bad version number in .class file (unable to load class service.ServiceImpl)
	at org.apache.catalina.loader.WebappClassLoader.findClassInternal(
	at org.apache.catalina.loader.WebappClassLoader.findClass(
	at org.apache.catalina.loader.WebappClassLoader.loadClass(
	at org.apache.catalina.loader.WebappClassLoader.loadClass(
	at org.springframework.util.ClassUtils.forName(
	... 40 more

Check that your compiler and loader are using the same version of Java.

11 thoughts on “Compiling Java 1.6 projects using Maven on Mac OS X”

  1. I’m pulling my hair out with this….I’ve double checked that my JAVA_HOME and PATH env vars are set up correctly, but I’m STILL getting the “Target 1.6 not supported” error. I want to use Java6 because I want to use the JAXB stuff without having to set up dependencies on these libraries in Maven under Java5.

    Any other tips that you can recommend for me? (email response preferred 🙂


  2. Ahhh…found it. I’m using Intellij IDEA, and the “Maven Runner” preference was set to use an internal Javac …. switching that to use Java6 fixed my problem 😉

  3. Dave I see. Generally I eliminate the IDE as a problem cause by switching to command line entirely and if it works then I know the IDE is at fault. Glad you found your solution. Merry Christmas! Isn’t it a bit of an odd time to be doing such things? I’m guilty of the same though 🙂

  4. Thank you very much! I was changing the JVM in the java tool in the Utility folder but nothing happened.

  5. Had the same problem on Windows. Tried the tips here, but didnt solved the problem. Only by changing the Java version in Eclipse to point to the Java 1.6 JDK instead of 1.6 JRE installation solved the problem (Window->Preferences->Java->Installed JREs, add JDK folder and tick the box).

Leave a Reply