gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 04:18:23 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com