Maven on Debian failed with JDK 1.9 – ClassFormatError

Today I ran into a problem with Maven under Debian GNU/Linux 9 (stretch). My Debian has OpenJDK 8 as also OpenJDK 9 installed. OpenJDK 9 is my default java version. My Maven version is 3.3.9.

mvn -version
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 9-Debian, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-9-openjdk-amd64
Default locale: de_DE, platform encoding: UTF-8
OS name: "linux", version: "4.9.0-6-amd64", arch: "amd64", family: "unix"

The problem is, that building one of my projects results in the following ClassFormat Error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project imixs-workflow-core: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: There was an error in the forked process
[ERROR] java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/xml/bind/JAXBException
[ERROR] at java.base/java.lang.ClassLoader.defineClass1(Native Method)
[ERROR] at java.base/java.lang.ClassLoader.defineClass(
[ERROR] at java.base/
[ERROR] at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(
[ERROR] at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(
[ERROR] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(
[ERROR] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(
[ERROR] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(
[ERROR] at java.base/java.lang.ClassLoader.loadClass(
[ERROR] at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
[ERROR] at java.base/java.lang.Class.privateGetDeclaredMethods(
[ERROR] at java.base/java.lang.Class.getMethodsRecursive(
[ERROR] at java.base/java.lang.Class.getMethod0(
[ERROR] at java.base/java.lang.Class.getMethod(
[ERROR] at org.apache.maven.surefire.util.ReflectionUtils.tryGetMethod(
[ERROR] at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isSuiteOnly(
[ERROR] at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isValidJUnit3Test(
[ERROR] at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.accept(
[ERROR] at org.apache.maven.surefire.common.junit4.JUnit4TestChecker.accept(
[ERROR] at org.apache.maven.surefire.util.DefaultScanResult.applyFilter(
[ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.scanClassPath(
[ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(
[ERROR] -> [Help 1]

The problem is a incompatibility of maven 3.3.9 with JDK 1.9. To solve this problem I switch to my OpenJDK 8 by setting the JAVA_HOME variable explicitly to JDK8 :

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/

After this change maven install works fine again in my projects.

To make the JAVA_HOME setting permanent follow this stepts.

1. find your preferred java version

ls -la /usr/lib/jvm/

2. edit the file /etc/profile and add the following line with the path to the JDK 8 you find before:

export JAVA_HOME="path to jdk8 that you found"

3. verify you maven installation

mvn -version

You maven should now be set to JDK8.

I hope this post will become obsolete in near future.