Java 使用另一个JDK编译Maven依赖项

Java 使用另一个JDK编译Maven依赖项,java,eclipse,maven,restlet,Java,Eclipse,Maven,Restlet,我有一个使用JDK1.5的项目(由于项目遗留问题),我想使用Restlet。目前,我在pom.xml中获得了当前构建部分: <build> <plugins> [...] <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin

我有一个使用JDK1.5的项目(由于项目遗留问题),我想使用Restlet。目前,我在pom.xml中获得了当前构建部分:

<build>

    <plugins>
        [...]
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-compiler-plugin</artifactId>
           <version>2.3.1</version>
           <configuration>
               <source>1.5</source>
               <target>1.5</target>
           </configuration>
       </plugin>       
    </plugins>

  </build>

  <repositories>
        <repository>
            <id>maven-restlet</id>
            <name>Restlet repository</name>
            <url>http://maven.restlet.com</url>
        </repository>
    </repositories>

    <properties>
        <restlet-version>2.2.1</restlet-version>
        <spring-version>3.1.1.RELEASE</spring-version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.restlet.jse</groupId>
            <artifactId>org.restlet</artifactId>
            <version>${restlet-version}</version>
        </dependency>
        <dependency>
            <groupId>org.restlet.jse</groupId>
            <artifactId>org.restlet.ext.jackson</artifactId>
            <version>${restlet-version}</version>
        </dependency>
    </dependencies>

我理解这个错误是因为我试图用Java5编译一个项目,但使用的是Java6库。如何使用或编译JDK 1.5中的依赖项?

如果不重新编译,就无法使用它们。为此,您需要源代码,在许多情况下还需要一些构建脚本来正确完成构建

java版本是.class文件的一部分,因为您告诉Maven为java 5编译,编译器将拒绝只使用版本高于49.0的.class文件(这是java 5的类文件版本)


因此,您需要具有49.0版本的.class文件,因此您需要重新编译库以及它的依赖项。在这个过程中,您甚至可能必须考虑到代码可能会使用较新的语言特性或JDK库,因此这可能是一项巨大的任务。在许多情况下,最好尝试提高使用Java 6或查找其他库的限制。

您必须使用旧版本。如果您查看,它会在2.2版本新闻中显示以下内容:

我们不再支持自Restlet Framework 1.0版以来的Java5。如果由于其他需求,您仍然需要支持Java5,我们鼓励您继续使用Restlet Framework 2.1

[ERROR] src/main/java/com/****/SomeFile.java:[3,-1] cannot access org.restlet.Component
bad class file: ****\.m2\repository\org\restlet\jse\org.restlet\2.2.1\org.restlet-2.2.1.jar(org/restlet/Component.class)
class file has wrong version 50.0, should be 49.0