Search code examples
javaeclipsemavenrestlet

Compile a Maven dependency with another JDK


I have a project using the JDK 1.5 (due to project legacy) and I want to use Restlet. For the moment I got the current build part in my 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>

When I am running mvn install through Eclipse, I get the following error:

[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

I understand the error is because I am trying to compile a project with Java 5 but using a Java 6 library. How can I use or compile my dependencies also with the JDK 1.5?


Solution

  • You will have to use an older version. If you check the Official Restlet Framework Blog, it says the following in the 2.2 version news:

    We no longer support Java 5 which has been the case since Restlet Framework version 1.0. If you still need to support Java 5 due to other requirements, we encourage you to keep using Restlet Framework 2.1.