2017-09-13 65 views
2

我试图用Maven构建3.2.5使用JDK 6(在Eclipse露娜的Java EE版),我不断收到如下因素的错误:Maven构建与JDK 6失败,因为UnsupportedClassVersionError

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下载了针对JDK 7编译的plexus-classworlds-2.5.2-sources.jar,这就是问题的原因。 Maven 3.2.5应该与JDK 6一起工作,所以我不明白发生了什么。

这里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> 
+0

这个问题有点棘手的解释。不要犹豫,要求精确。 –

+0

plexus-classworlds-2.5.2-sources.jar降级构建在java中的jar版本6 – Kick

+0

在这里提供'pom.xml'配置将很有用。 – Andremoniy

回答

1

一个错误消息,如

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

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

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

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

,并根据Maven的是如何启动,您可以强制Maven的版本是:

  • 命令行:设置M2_HOME环境变量指向安装并确保执行的是3.2。 5(PATH环境变量)
  • IDE:检查IDE是否配置为使用您需要的Maven版本。看怎么做here for IntelliJthere for Eclipse