【问题标题】:Eclipse Maven Build Error invalid target releaseEclipse Maven Build Error 无效的目标版本
【发布时间】:2023-03-06 16:54:01
【问题描述】:

我是第一次使用 Maven(在 Eclipse 中)。我想包括 HakariCP 到我的项目。每次我尝试构建我的项目时,都会收到以下错误消息:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:compile (default-compile) on project WindowPanel: Fatal error  compiling: invalid target release: 1.8 -> [Help 1]

这是我的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>me.gustavwww</groupId>
  <artifactId>WindowPanel</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>WindowPanel</name>
  <description>A Windows Server Panel</description>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <repositories>
    <repository>
      <id>spigot-repo</id>
      <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
    </repository>
  </repositories>
  <dependencies>
    <dependency>
      <groupId>org.spigotmc</groupId>
      <artifactId>spigot-api</artifactId>
      <version>1.10.2-R0.1-SNAPSHOT</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>com.zaxxer</groupId>
      <artifactId>HikariCP</artifactId>
      <version>LATEST</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

提前致谢!

编辑:我所做的只是将我的 JDK 更新到最新的version

【问题讨论】:

  • 假设您使用的是 JDK 1.7 而不是 JDK 8?
  • 不,我正在使用 jre1.8.0_31
  • 从 cmd 运行这个:mvn -version 并告诉我们它打印的内容。
  • 已解决,已编辑..
  • 是的..JRE 而不是 JDK ;-)

标签: java maven


【解决方案1】:

如果您在 Eclipse 中将 JRE 默认设置为 1.7,则需要在 Run Configurations 中指定 1.8。转到“运行 > 运行配置...”并选择您遇到问题的 Maven 构建。然后单击 JRE 选项卡并选择执行环境 Java 1.8。

【讨论】:

    【解决方案2】:

    如果您确实需要针对 Java 8 进行编译,请阅读 this question and answer

    它们提供了不止一种方法来强制 Maven 使用特定版本的 Java。

    【讨论】:

      猜你喜欢
      • 2021-04-29
      • 2018-12-30
      • 2012-02-18
      • 1970-01-01
      • 2015-10-14
      • 1970-01-01
      • 2013-11-22
      • 2015-12-19
      • 1970-01-01
      相关资源
      最近更新 更多