java - Maven 构建失败,如何在 Eclipse 中将 -source 1.5 更改为 -source 7 或更高版本

标签 java eclipse maven java-7

我在 Eclipse 中有一个 Maven 项目。在构建其显示错误时:

--- maven-clean-plugin:2.5:clean (default-clean) @ DataMasking ---
[INFO] Deleting D:\workspaces\Datamasking\DataMasking\target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ 
DataMasking ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered 
resources, i.e. build is platform dependent!
[INFO] Copying 22 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ DataMasking 
---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, 
i.e. build is platform dependent!
[INFO] Compiling 78 source files to 
D:\workspaces\Datamasking\DataMasking\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR]/D:/workspaces/Datamasking/DataMasking/src/main/java/com/medicare/mask/dao/ApplicationDao.java:[197,21] try-with-resources is not supported in -source 1.5
 (use -source 7 or higher to enable try-with-resources)
[ERROR] /D:/workspaces/Datamasking/DataMasking/src/main/java/main.java:[60,21] try-with-resources is not supported in -source 1.5
(use -source 7 or higher to enable try-with-resources)
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ---------------------------------------------------------------------- 
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.451 s
[INFO] Finished at: 2018-06-14T14:26:40+05:30
[INFO] Final Memory: 7M/20M

错误指向时的代码。通常在 eclipse 中显示编译错误,并建议将项目编译更改为 JavaSE-1.7,我已更改。当 Maven 构建显示错误时,它在 Eclipse 中没有显示任何红线。

try (FileWriter fw = new FileWriter(filesPath + "DataMaskOutput.txt", true);
        BufferedWriter bw = new BufferedWriter(fw);
        PrintWriter out = new PrintWriter(bw)) {
    out.println(applId + "-->" + updateApplSeedNbr);
    out.close();
} catch (IOException e) {
    e.printStackTrace();
}

最佳答案

根据 maven-compiler-plugin docs你可以使用 <properties>pom.xml :

<project>
  ...
  <properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>
  ...
</project>

关于java - Maven 构建失败,如何在 Eclipse 中将 -source 1.5 更改为 -source 7 或更高版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50853809/

相关文章:

android - 适用于 Mac 的 ADT bundle : Eclipse cannot be started

java - 在Java中以编程方式终止selenium服务器进程

java - 结合groovy和java编译报错(使用maven)

eclipse - Eclipse JDK 警告的 Maven 集成

java - 在Java中使用Thread对象的内在锁可以吗?

java - 如何使用 Heroku eclipse 插件?遇到错误

java - 在 Spring MVC 应用程序中查找内存泄漏

java - Spring Boot - 来自 JNDI : NoInitialContextException: Need to specify class name in environment or system property 的数据源

java - 按像素在其图标上移动 JButton 文本

Java ZipInputStream 异常在代码执行之前抛出