Maven build with JDK 6 fails due to UnsupportedClassVersionError

278
September 13, 2017, at 9:50 PM

I'm trying to build with Maven 3.2.5 using the JDK 6 (in Eclipse Luna, Java EE Edition), and I keep getting the folowing error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:254)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
    at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(Launcher.java:144)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:266)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

After investigations, Maven downloads plexus-classworlds-2.5.2-sources.jar, which is compiled for the JDK 7, and that's the cause of the problem. Maven 3.2.5 is supposed to work with the JDK 6, so I don't understand what's happening.

Here the pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>fr.sacem.fwk</groupId>
        <artifactId>frmwk-parent</artifactId>
        <version>5.3.13</version>
    </parent>
    <artifactId>sacem-fwkweb</artifactId>
    <packaging>jar</packaging>
    <name>Sacem Framework Web</name>
    <description>Socle technique de la Sacem</description>
    <dependencies>
           <!-- FwkCore -->
        <dependency>
            <groupId>fr.sacem.fwk</groupId>
            <artifactId>sacem-fwkcore</artifactId>
            <version>${project.version}</version>
        </dependency>
        <!-- Wesso -->
        <dependency>
            <groupId>fr.sacem.admap</groupId>
            <artifactId>wesso-api</artifactId>
            <version>3.5.0</version>
        </dependency>
        <!-- Apache Commons -->
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-digester</groupId>
            <artifactId>commons-digester</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-jxpath</groupId>
            <artifactId>commons-jxpath</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
        </dependency>
        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
        </dependency>
        <!-- 
        <dependency>
            <groupId>commons-resources</groupId>
            <artifactId>commons-resources</artifactId>
            <version>X.Y.Z</version>
        </dependency>
         -->
        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
        </dependency>

        <!-- Gestion des Logs -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </dependency>
        <!-- POI -->
        <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi</artifactId>
        </dependency>
        <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi-contrib</artifactId>
        </dependency>
        <!-- Struts -->
        <dependency>
              <!-- 
              <groupId>struts</groupId>
               -->
              <groupId>fr.sacem.struts</groupId>
            <artifactId>struts</artifactId>
        </dependency>
        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
        </dependency>
        <!-- JUnit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>fr.sacem.fwk</groupId>
            <artifactId>fwkunit</artifactId>
            <scope>test</scope>
        </dependency>
         <!-- API JavaEE
         <dependency>
             <groupId>javaee</groupId>
             <artifactId>javaee-api</artifactId>
             <scope>provided</scope>
         </dependency>
          -->
         <!-- API Servlet -->
         <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
             <scope>provided</scope>
         </dependency>
        <!-- API JSP -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- API JTA -->
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <scope>provided</scope>
        </dependency>
        <!-- YUI Compressor -->
        <dependency>
            <groupId>com.yahoo.platform.yui</groupId>
            <artifactId>yuicompressor</artifactId>
            <version>2.4.7</version>
            <scope>provided</scope>
            <type>jar</type>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <frmwk.project.build.sourceEncoding>${project.build.sourceEncoding}</frmwk.project.build.sourceEncoding>
        <frmwk.project.copyright>Copyright 2002-2015 SACEM.</frmwk.project.copyright>
        <frmwk.web.directory.build>${basedir}/build</frmwk.web.directory.build>
        <frmwk.web.directory.source.java>${basedir}/WEB-INF/sources/java/dev</frmwk.web.directory.source.java>
        <frmwk.web.directory.classes>${frmwk.web.directory.build}/classes</frmwk.web.directory.classes>
        <frmwk.web.directory.test.sources>${basedir}/WEB-INF/sources/java/tests</frmwk.web.directory.test.sources>
        <frmwk.web.directory.test.config>${basedir}/WEB-INF/config</frmwk.web.directory.test.config>
        <frmwk.web.directory.test.resources>${basedir}/WEB-INF/ressources</frmwk.web.directory.test.resources>
        <frmwk.web.directory.test.classes>${frmwk.web.directory.build}/test-classes</frmwk.web.directory.test.classes>
        <frmwk.web.directory.deploy>${basedir}/WEB-INF/deploiement</frmwk.web.directory.deploy>
        <frmwk.web.directory.templates>${frmwk.web.directory.deploy}/script/templates</frmwk.web.directory.templates>
        <frmwk.resources.jsp>${project.artifactId}-${project.version}-jsp</frmwk.resources.jsp>
        <frmwk.resources.tools.yuicompressor>${maven.dependency.com.yahoo.platform.yui.yuicompressor.jar.path}</frmwk.resources.tools.yuicompressor>
    </properties>
    <build>
        <directory>${frmwk.web.directory.build}</directory>
        <sourceDirectory>${frmwk.web.directory.source.java}</sourceDirectory>
        <resources>
            <resource>
                <directory>${frmwk.web.directory.source.java}</directory>
                <filtering>false</filtering>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
        <outputDirectory>${frmwk.web.directory.classes}</outputDirectory>
        <testSourceDirectory>${frmwk.web.directory.test.sources}</testSourceDirectory>
        <testResources>
            <testResource>
                <directory>${frmwk.web.directory.test.resources}</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*</include>
                </includes>
            </testResource>
            <testResource>
                <directory>${frmwk.web.directory.test.config}</directory>
                <filtering>false</filtering>
                <includes>
                    <include>**/*</include>
                </includes>
            </testResource>
        </testResources>
        <testOutputDirectory>${frmwk.web.directory.test.classes}</testOutputDirectory>
        <plugins>
            <!-- - - - - - - - - - - - - - - - - - 
                    JAVADOC
                 - - - - - - - - - - - - - - - - - -->
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-javadoc-plugin</artifactId>
              <configuration>
                    <javadocExecutable>${frmwk.javadoc.executable}</javadocExecutable>
                    <docfilessubdirs>true</docfilessubdirs>
                    <locale>fr_FR</locale>
                    <version>true</version>
                    <author>true</author> 
                    <use>true</use> 
                    <private>false</private> 
                    <doctitle>${project.name} ${project.version}</doctitle> 
                    <windowtitle>${project.name} ${project.version}</windowtitle> 
                    <header>&lt;b&gt;${project.name} ${project.version}&lt;/b&gt;</header> 
                    <bottom>${frmwk.project.copyright}</bottom>
                    <stylesheetfile>${frmwk.web.directory.templates}/javadoc-stylesheet/stylesheet.css</stylesheetfile>
              </configuration>
              <executions>
                <execution>
                  <id>attach-javadocs</id>
                  <goals>
                    <goal>jar</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>
            <!-- - - - - - - - - - - - - - - - - - 
                    COMPILATION JAVA 1.6
                 - - - - - - - - - - - - - - - - - -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${frmwk.compile.source}</source>
                    <target>${frmwk.compile.target}</target>
                    <verbose>${frmwk.compile.verbose}</verbose>
                    <debug>${frmwk.compile.debug}</debug>
                    <encoding>${frmwk.project.build.sourceEncoding}</encoding>
                    <showDeprecation>${frmwk.compile.deprecation}</showDeprecation>
                    <optimize>${frmwk.compile.optimize}</optimize>
                    <fork>${frmwk.compile.fork}</fork>
                    <executable>${frmwk.compile.executable}</executable>
                    <compilerVersion>${frmwk.compile.compilerVersion}</compilerVersion>
                </configuration>
            </plugin>
            <!-- - - - - - - - - - - - - - - - - - 
                    SOURCES JAVA
                 - - - - - - - - - - - - - - - - - -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- ================================= 
                    PREPARER LIVRAISON AMELY
                ================================= -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <!-- - - - - - - - - - - - - - - - - - 
                          target: copy-jars-to-delivery-dir                      
                         - - - - - - - - - - - - - - - - - -->
                    <execution>
                        <id>copy-jars-to-delivery-dir</id>
                        <phase>install</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target name="Jar" description="Livrer la librairie">
                                <!-- S'assurer de l'existence du dossier de livraison -->
                                <mkdir dir="${frmwk.project.delivery.dir}" />
                                <!-- Copier les jar -->
                                <copy todir="${frmwk.project.delivery.dir}" overwrite="true" >
                                    <fileset dir="${frmwk.web.directory.build}">
                                        <filename name="*.jar"/>
                                    </fileset>
                                </copy>
                            </target>
                        </configuration>
                    </execution>
                    <!-- - - - - - - - - - - - - - - - - - 
                          target: copy-javadoc-to-delivery-dir                      
                         - - - - - - - - - - - - - - - - - -->
                    <execution>
                        <id>copy-javadoc-to-delivery-dir</id>
                        <phase>install</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target name="Javadoc" description="Livrer la documentation en ligne (api)">
                                <!-- S'assurer de l'existence du dossier dedestination -->
                                <mkdir dir="${frmwk.project.delivery.dir}/Javadoc/${project.artifactId}" />
                                <!-- Copier le dossier -->
                                <copy todir="${frmwk.project.delivery.dir}/Javadoc/${project.artifactId}" overwrite="true" >
                                    <fileset dir="${frmwk.web.directory.build}/apidocs">
                                        <filename name="**/*"/>
                                    </fileset>
                                </copy>
                                <!-- Copier le template de dossier Amely -->
                                <filter token="projectVersion" value="${project.version}"/>
                                <filter token="projectName"    value="${project.artifactId}"/>
                                <copy file="${frmwk.web.directory.templates}/amely/Javadoc/project.name/folder.amely"
                                      tofile="${frmwk.project.delivery.dir}/Javadoc/${project.artifactId}/folder.amely"
                                      filtering="true"/>
                            </target>
                        </configuration>
                    </execution>
                    <!-- - - - - - - - - - - - - - - - - - 
                          target: zip-sources-non-public                     
                         - - - - - - - - - - - - - - - - - -->
                    <execution>
                        <id>zip-sources-non-public</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target name="SourcesNonPublic" description="Livrer les sources (non public)">
                                <mkdir dir="${frmwk.project.delivery.dir}/SourcesNonPublic" />
                                <!-- Zipper l'intégralité du projet -->
                                <zip destfile="${frmwk.project.delivery.dir}/SourcesNonPublic/${project.artifactId}_${project.version}.srcnonpublic.zip">
                                    <fileset dir="${basedir}">
                                        <include name=".settings/**/*"/>
                                        <include name="commun/**/*"/>
                                        <include name="fwk/**/*"/>
                                        <include name="WEB-INF/**/*"/>
                                        <include name=".*"/>
                                        <exclude name="build/"/>
                                        <exclude name="*.log"/>
                                    </fileset>
                                </zip>
                            </target>
                        </configuration>
                    </execution>
                    <!-- - - - - - - - - - - - - - - - - - 
                          target: fwkweb-jsp-zip                      
                         - - - - - - - - - - - - - - - - - -->
                    <execution>
                        <id>fwkweb-jsp-zip</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target name="jsp-build-zip">
                                <delete dir="${frmwk.project.delivery.dir}/${frmwk.resources.jsp}.zip" failonerror="false" />
                                <zip zipfile="${frmwk.project.delivery.dir}/${frmwk.resources.jsp}.zip">
                                    <zipfileset dir="${basedir}" prefix="src/main/webapp">
                                        <include name="fwk/**/*"/>
                                    </zipfileset>
                                    <zipfileset dir="${basedir}/WEB-INF/ressources" prefix="src/main/resources">
                                        <include name="*.properties"/>
                                    </zipfileset>
                                </zip>
                            </target>
                        </configuration>
                    </execution>
            </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <!-- ================================= 
                          target: FRMWK-${project.version}.zip              
                         ================================= -->
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${frmwk.project.delivery.dir}/${frmwk.resources.jsp}.zip</file>
                                    <type>zip</type>
                                    <classifier>jsp</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <!--
        - - - - - - - - - - - - - - - - - - -
            Profile: FRMWK
        - - - - - - - - - - - - - - - - - - - -
        -->
        <profile>
            <id>FRMWK</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- Paramètre de build des modules FRMWK -->
                <frmwk.compile.executable>${JAVA_1_6_HOME}/bin/${JAVAC_EXE}</frmwk.compile.executable>
                <frmwk.javadoc.executable>${JAVA_1_6_HOME}/bin/${JAVADOC_EXE}</frmwk.javadoc.executable>
                <!-- Options de compilation -->
                <frmwk.compile.source>1.6</frmwk.compile.source>
                <frmwk.compile.target>${frmwk.compile.source}</frmwk.compile.target>
                <frmwk.compile.verbose>true</frmwk.compile.verbose>
                <frmwk.compile.debug>true</frmwk.compile.debug>
                <frmwk.compile.deprecation>true</frmwk.compile.deprecation>
                <frmwk.compile.optimize>true</frmwk.compile.optimize>
                <frmwk.compile.fork>true</frmwk.compile.fork>
                <frmwk.compile.compilerVersion>${frmwk.compile.source}</frmwk.compile.compilerVersion>
                <frmwk.project.delivery.dir>${FRMWK_DELIVRY_HOME}/V${project.version}</frmwk.project.delivery.dir>
            </properties>
        </profile>
    </profiles>
</project>
Answer 1

An error message such as

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0

will always indicate that a code compiled using JDK 7 is being executed by a non-compatible JRE version (most probably 6 or lower).

In your particular use-case (project needs JDK6), you have to ensure that the maximum Maven version used is 3.2.5 (the current latest official JDK6-compliant Maven version).

If your system hosts different versions of Maven, you will here have to force the version used.

And, depending on how Maven is launched, you can force that Maven version by:

  • Command-line: set M2_HOME environment variable to point to that installation and be sure the executable is 3.2.5 (PATH environment variable)
  • IDE: check that the IDE is configured to use the Maven version you need. See how to do that here for IntelliJ and there for Eclipse
READ ALSO
ValueAnimator to animate a large value (long)

ValueAnimator to animate a large value (long)

I am trying to animate a large value (over the int max value) using ValueAnimator but it only seems to animate an int (or float, but it looks awful eg

214
How to create a calendar with the default GMT hours in java

How to create a calendar with the default GMT hours in java

I'm getting a long from a server that I have to parse into a dateI'm using a calendar to do so

333
How to get all of one entity but filtered relation in JPQL

How to get all of one entity but filtered relation in JPQL

I have a OneToMany relation between to entities: Area and ReservationArea has many reservations (or none) and Reservation has one Area

315
Java UI thread blocked - Out of Memory error

Java UI thread blocked - Out of Memory error

In my application, I get messages every second, which contains the altitude, speed and headingEach time, I get the message, I need to generate a symbol (jpg) and show it in UI of the desktop application

315