I needed to change my project to Java 1.7. This causes an error that lots of folks are seeing:
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.reflect.InvocationTargetException; nested exception is java.lang.reflect.InvocationTargetException: null
...
Caused by: java.lang.UnsupportedClassVersionError: com/.../AppTest : Unsupported major.minor version 51.0
I've seen the many pages saying to configure the maven-surefire-plugin jvm, but this isn't working for me.
Also, my default java IS 1.7, so I don't understand why this should be needed anyway.
$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
$ javac -version
javac 1.7.0_45
Also on OS X I thought we're not supposed to be using variables and symlinks, the javahome subsystem is supposed to keep this all sorted out.
$ javahome
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
Attempts and errors:
Attempted Fix 1:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<jvm>${env.JAVA_HOME_7}/bin/java</jvm>
</configuration>
</plugin>
Error 1:
/bin/sh: ${env.JAVA_HOME_7}/bin/java: bad substitution
Attempted Fix 2:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<jvm>${jdk.home}/bin/java</jvm>
</configuration>
</plugin>
Error 2:
/bin/sh: ${jdk.home}/bin/java: bad substitution
Questions:
- Java 7 is the default, so why should I need to do anything?
- On OSX, what is the "best practice" for maven?
- The second failure seems really odd, shouldn't
${jdk.home}
be almost "hardwired" in maven? - How did Maven get so broken? It puts surefire in the mix, I didn't. And they have directives for setting Java 1.7. So how could this even happen? Is it being worked on?
I eventually did find a workaround:
# I'd rather not put this in my .profile
export JAVA_HOME=`javahome`
# Then in pom.xml I put:
<jvm>${env.JAVA_HOME}/bin/java</jvm>