You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

STS是否支持Java 8?使用JDK 8编译项目报错求助

STS对Java 8项目的支持及编译错误解决

STS(Spring Tool Suite)完全支持Java 8项目,可直接在STS中配置JDK 8作为项目的编译、运行环境。

针对你遇到的两个编译错误,具体原因和解决方法如下:

1. fatal error compiling invalid flag: release

  • 原因:--release是JDK 9及以上版本才支持的编译参数,你的示例项目构建配置(如Maven的pom.xml)中使用了该参数,JDK 8无法识别。
  • 解决:
    • 打开项目的构建配置文件,以Maven为例,找到maven-compiler-plugin的配置段,将<release>标签替换为JDK 8兼容的<source>和<target>配置:
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.1</version>
          <configuration>
              <source>1.8</source>
              <target>1.8</target>
          </configuration>
      </plugin>
      
    • Gradle项目则修改sourceCompatibility = 1.8、targetCompatibility = 1.8,并移除--release相关配置。

2. No goals have been specified for this build.

  • 原因:执行Maven命令时未指定构建目标(如编译、打包等),Maven无法确定要执行的操作。
  • 解决:
    • 执行Maven命令时明确添加目标,比如mvn compile(编译项目)或mvn clean install(完整构建)。
    • 也可在项目pom.xml中添加默认目标配置,避免每次手动输入:
      <build>
          <defaultGoal>compile</defaultGoal>
      </build>
      

内容的提问来源于stack exchange,提问作者Devinder Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 01:12:35