简体   繁体   English

-source 1.5 错误中不支持 java 1.7+

[英]java 1.7+ is not supported in -source 1.5 errors

I'm getting all sort of java errors not supported in -source 1.5 when creating my Maven Install in eclipse.在 Eclipse 中创建我的 Maven 安装时,我遇到了 -source 1.5 中不支持的所有类型的 java 错误。 There is nothing wrong with my code.我的代码没有任何问题。

Errors follows:错误如下:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1
[23,62] multi-catch statement is not supported in -source 1.5 
[241,29] try-with-resources is not supported in -source 1.5
[156,64] diamond operator is not supported in -source 1.5

My pom configuration follows:我的 pom 配置如下:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.3</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <encoding>UTF-8</encoding>
        </configuration>
    </plugin>

Add the following lines in your pom.xml file should resolve your problem.在 pom.xml 文件中添加以下几行应该可以解决您的问题。

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

If you may take in consideration the advises that were provided to you.如果您可以考虑提供给您的建议。 You would have 2 options to choose from:您将有 2 个选项可供选择:

Option 1) If you keep the maven-war-plugin.选项 1)如果您保留 maven-war-plugin。 Update version to the latest then add the properties with the compiler info and sourceEncoding but remove the configuration lines :将版本更新到最新,然后添加带有编译器信息和 sourceEncoding 的属性,但删除配置行

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
    
    ..
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.3.1</version>
    </plugin>
    ..
</build>

Option 2) If you replace maven-war-plugin with the maven-compiler-plugin ** There are no need to add/replace the source, target and encoding to the properties**.选项 2)如果将 maven-war-plugin 替换为 maven-compiler-plugin ** 无需在属性中添加/替换源、目标和编码**。 Make sure to update the version to the latest:确保将版本更新到最新:

<build>
    ..
    <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>
            <encoding>UTF-8</encoding>
        </configuration>
    </plugin>
    ..
</build>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM