18
votes

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

4
Is maven compiler plugin set to 1.8? It default to 1.5 if you don't declare it to override the java versionPaul Samsotha
@peeskillet where can i view it?BrokenFrog
In you pom file. It should be under <plugins> If you don't see it, you can and it. Just google maven-compiler-plugin. It not difficult to add. After you add it, update the projectPaul Samsotha
@peeskillet added the maven-compiler-plugin version 3.3 to pom.xml and updated the project. Still got the same errorBrokenFrog
Sorry I was on my tablet, couldn't get you some code. But for the plugin, under the </version> add <configuration><source>1.8</source><target>1.8</target></configuration>, then Right click project -> Maven -> Update ProjectPaul Samsotha

4 Answers

36
votes

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.

3
votes

I know the topic is old but I had the same problem and it's hard to find informations on it. So set the properties wasn't enough for me, I had also to delete the project from Eclipse, then delete the .project file and reimport the project as a Maven project (even if I created it as a Maven project already) like it is answer on this topic.

2
votes

those who are doing with properties way and if it is not working do this step.
in Pom.xml

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

After that do this:

  project folder-> maven--> update project--> check force update-->ok

After that do

 project folder-->run as-->mvn build with goal eclipse:eclipse

you don't need to re-import the project as suggested in other answer/

0
votes

Just got to the path of the project and go to settings and find the xml file named "org.eclipse.wst.common.project.facet.core" and change the version of java from there