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

依然范特西╮ 提交于 2021-01-20 15:11:15

问题


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


回答1:


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.




回答2:


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.




回答3:


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/




回答4:


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



来源:https://stackoverflow.com/questions/30082476/eclipse-jax-rs-rest-web-services-2-0-requires-java-1-6-or-newer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!