【问题标题】:Java compiler level does not matchJava 编译器级别不匹配
【发布时间】:2012-07-02 10:18:49
【问题描述】:

我在 eclipse helios 中使用 jsf2 hibernate 4.1.4、spring 3.1 和 maven 3。但是当我尝试将依赖添加到 POM 时出现此错误。

Java compiler level does not match the version of the installed Java project facet.

这是什么意思?我该如何解决这个错误?

我也有这个警告:

Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.   

我的 POM:

<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>com.integrate</groupId>
  <artifactId>integrate</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>integrate</name>
  <dependencyManagement>
    <dependencies>
    </dependencies>
  </dependencyManagement>
  <properties>
  <spring.version>3.1.0.RELEASE</spring.version>
 </properties>

 <dependencies>

  <!-- Spring 3 dependencies -->
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-core</artifactId>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context</artifactId>
   <version>${spring.version}</version>
  </dependency> 

  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-web</artifactId>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-tx</artifactId>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-orm</artifactId>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>

  <!-- JSF dependencies -->
  <dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.1.6</version>
  </dependency>

  <dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>2.1.6</version>
  </dependency>

  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>jstl</artifactId>
   <version>1.2</version>
  </dependency>


  <!-- Hibernate dependencies -->
  <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-core</artifactId>
   <version>4.1.4.Final</version>
  </dependency>

  <dependency>
   <groupId>javassist</groupId>
   <artifactId>javassist</artifactId>
   <version>3.12.1.GA</version>
  </dependency>

  <!-- oracle Connector dependency -->
  <dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0.3</version>
</dependency>
<!-- c3p0 dependency -->
      <dependency>
       <groupId>c3p0</groupId>
       <artifactId>c3p0</artifactId>
       <version>0.9.1.2</version>
  </dependency>  


 </dependencies>

图片:

【问题讨论】:

  • 在 github 上使用粘贴箱或 gist 发布您的 pom.xml 或指向它的链接
  • 您需要安装 JDK 1.5 并在偏好设置->jre
  • @J-16SDiZ,我安装了 jdk 1.6
  • @sami,没有。您只需要 1.5 并将其设为默认值(在 eclipse 偏好中)。
  • @J-16SDiZ,我优先标记了 jre7。

标签: java eclipse jakarta-ee maven maven-3


【解决方案1】:

只需将带有 ma​​ven-compiler-pluginbuild 部分添加到您的 pom.xml。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>

然后你应该配置项目的构建路径。

或者您可以从 Eclipse 工作区中删除项目(而不从文件系统中删除),从项目中删除 Eclipse 的设置(.project、.classpath 和 .settings 文件和文件夹),然后将您的项目重新导入为现有的 Maven项目到您的 IDE。 Eclipse 将正确地重新生成其设置。

【讨论】:

  • 我在上面编辑了我的评论。请检查您的 pom.xml 在项目根目录下运行 mvn clean compile 的一致性。如果没问题,您可以选择一个合适的案例来配置您的项目类路径设置或删除上面评论中提到的 eclipse 设置。
【解决方案2】:

请检查与您的项目有关的项目方面(右键单击项目/Properties/Project Facets/Java)。

只是您系统中安装的 java 版本与您在项目的项目方面中指定的 java 版本可能不匹配。

【讨论】:

  • in priject facet java 版本是 1.6
  • 那么它是您系统中安装的那个吗?
  • 我已经在我的系统中安装了 jdk 7u1
  • 因为你的项目是 1.6,你应该安装 java 6 而不是 7
【解决方案3】:

在 D:\maven-2.2.1\conf toolchains.xml 中指定 Maven 的 java 版本

<?xml version="1.0" encoding="UTF-8"?>
<toolchains>
<toolchain>
    <type>jdk</type>
    <provides>
        <version>1.5</version> <!--This should be same as is configured via the toolchains plugin -->
        <vendor>ibm</vendor> <!--This should be same as is configured via the toolchains plugin -->
    </provides>
    <configuration>
        <jdkHome>C:\Program Files\Java\jdk1.5.0</jdkHome>
    </configuration>
</toolchain>
</toolchains>

【讨论】:

    猜你喜欢
    • 2016-04-10
    • 2011-12-04
    • 1970-01-01
    • 2016-09-25
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多