JRE系统库 - 不支持的major.minor版本52.0

时间:2015-08-24 13:39:57

标签: java eclipse maven java-7 m2eclipse

我将java 8降级为java 7,我无法运行我的项目。

我的日食配置是:

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

我的pom.xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>br.usp.icmc.jenkins.saucelabs</groupId>
    <artifactId>JenkinsSaucelabs</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>JenkinsSaucelabs</name>
    <description>JenkinsSaucelabs</description>

    <dependencies>
        <dependency>
           <groupId>junit</groupId>
           <artifactId>junit</artifactId>
           <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20141113</version>
        </dependency>
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <!-- Dependente da versão da JDK -->
            <classifier>jdk15</classifier>
        </dependency>
        <!-- Jersey -->
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.11</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-servlet</artifactId>
            <version>1.11</version>
        </dependency>

        <!-- Json -->
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>1.11</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.19</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <version>0.11</version>
        </dependency>

        <dependency>
            <groupId>com.restfb</groupId>
            <artifactId>restfb</artifactId>
            <version>1.11.0</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.3.1</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>TesteJSONSauceLabs</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

我测试了帖子的替代方案:

Eclipse JRE System Library [J2SE-1.5]

No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Stacktracer:

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/json/JSONObject : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at br.usp.icmc.teste.ConnectionRestClient.getSaucelabsJobsByID(ConnectionRestClient.java:30)
    at br.usp.icmc.teste.TestePrincipal.main(TestePrincipal.java:8)

为什么我收到Unsupported major.minor版本52.0的UnsupportedClassVersionError异常?我哪里错了?

2 个答案:

答案 0 :(得分:1)

您正在使用不正确的java版本运行应用程序,或者您正在使用的某些依赖项是为java 8编译的。

检查您的JAVA_HOME是否指向正确的Java安装,以及Eclipse是否真正使用Java 7.

答案 1 :(得分:1)

更改了POM文件中使用的Java版本后,是否刷新了Eclipse中项目的依赖项?

在Eclipse Luna(可能还有Eclipse Mars)中,可以通过按Alt-F5或右键单击Maven项目,选择Maven菜单,然后单击Update Projects按钮来完成。

这会打开一个新的对话框,如下所示:

Update Maven Project

应显示当前Eclipse工作区中的所有Maven项目。在上面的示例中,这是一个包含多个子项目的父项目。

您应该在工作区中选择所有Maven项目,然后单击“确定”。

这应该强制Maven刷新项目的所有依赖项......包括Maven试图用于项目的Java版本。