Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse JAX-RS (REST Web Services) 2.0 requires Java 1.6 or newer

i'm new to web service and i'm trying to do a project using jax-rs rest and spring in eclipse. I use java 1.8 but eclipse shows me an error that jax-rs 2.0 requires java 1.6 or newer error and my project won't work

This is the project explorer and error's screenshot. I tried to google it but can't get any english solutions

Eclipse screenshot

Edit : It seems like the screenshot's quality is low if i try to display it so here is the imgur link for the screenshot for better quality http://i.imgur.com/YYyoeUX.png

like image 260
BrokenFrog Avatar asked May 06 '15 16:05

BrokenFrog


1 Answers

Maven projects come with a bunch of plugins applied implicitly to the build. One of them being the maven-compiler-plugin. Unfortunately the Java version for the plugin defaults to 1.5. Most Maven project you see will override the Java version simply by declaring the plugin (in your pom.xml file) and configuring the Java version

  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
  </build>

Eclipse (with m2e plugin) will set the compiler compliance level to the setting in the plugin. You can view this by going to

Right click on the project -> properties -> Java Compiler -> Look at compliance level

UPDATE

Instead of the above compiler plugin configuration, you can also simply just do

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

The default plugin configuration will look for these properties. It's a lot less verbose than re-declaring the plugin.

After adding the properties or the compiler plugin to your pom.xml, you might need to update the project. See Manish's answer.

like image 185
Paul Samsotha Avatar answered Sep 18 '22 15:09

Paul Samsotha