当前位置: 首页 > 知识库问答 >
问题:

使用JDK 6构建的Maven由于Unsupport tedClassVersionError失败

宇文梓
2023-03-14

我试图使用JDK 6(在Eclipse Luna,Java EE版中)构建Maven 3.2.5,但我一直收到以下错误:

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)

经过调查,Maven下载了plexus-classworlds-2.5.2-sources。jar,它是为JDK 7编译的,这就是问题的原因。Maven 3.2.5应该与JDK 6一起工作,所以我不知道发生了什么。

这是绒球.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>

共有1个答案

壤驷宏才
2023-03-14

一条错误消息,如

线程“main”java.lang.UnsupportedClassVersionError:org/apache/maven/cli/MavenCli中出现异常:不支持的主。次要版本51.0

将始终指示使用JDK 7编译的代码正在由不兼容的JRE版本(最可能是6或更低版本)执行。

在您的特定用例中(项目需要JDK6),您必须确保使用的最大Maven版本为3.2.5(当前最新的官方JDK6兼容Maven版本)。

如果您的系统托管不同版本的 Maven,则必须在此处强制使用的版本。

而且,根据Maven的启动方式,您可以通过以下方式强制使用Maven版本:

  • 命令行:将M2_HOME环境变量设置为指向该安装,并确保可执行文件为3.2.5(路径环境变量)
  • IDE:检查IDE是否配置为使用所需的Maven版本。查看如何在IntelliJ和Eclipse中实现这一点
 类似资料:
  • 我使用Gradle 4.10.2(但使用最新版本让它工作会很好)。这是我的gradle文件: 当我执行时,它会失败并出现很多错误。这些错误都是由于没有找到lombok自动生成的getter、setter等。如何解决这些错误?我看过其他关于这个问题的帖子,他们都建议将lombok依赖项添加为 使现代化 以下是我得到的几个错误: 日志应该来自注释。并且来自于在CarDto上注释的@Builder(Bu

  • 回溯(最近一次通话最后一次): [3/132]ACTION//chrome/android:chrome_java_resources(//build/tools chain/android:android_clang_arm)忍者:构建停止:子命令失败。 编辑 历史是一排。xml 乌尔希斯拉。JAVA 唯一的方法不是显示错误的整个类 我之前得到的错误突然消失,现在突然构建停止。 错误: ../.

  • 我正在TFS2015中运行一个构建,我得到了这个错误: 在org.apache.maven.lifecycle.internal.mojoexecutor.execute(mojoexecutor.java:217) 原因:org.apache.maven.plugin.MojoExecutionException:编译时出现致命错误 222 2018-07-25T11:22:37.0150577

  • [错误]D:...\spark-test\java-gett-start\src\main\java\main.java:[73,35]错误:源代码1.5中不支持lambda表达式 这是一个heroku示例java项目,在System.properties文件中设置了java版本:java.runtime.version=1.8 具体行如下:

  • 问题内容: 我有下面的简单代码,用于使用maven测试findbugs NonNull批注。 我执行“ mvn clean install site”,得到目录target / site / css和target / site / images,但仅此而已。我原本希望得到一份报告,说println(null)违反了NonNull条件。 我需要怎么做才能得到那个报告? 另外,如果存在NonNull违

  • 我已经更新了firebase-auth依赖版本,但gradle构建总是失败。它在中运行良好 项目级别分级文件