简体   繁体   English

Apache Maven:-source 1.5中不支持Diamond运算符

[英]Apache Maven: Diamond operator is not supported in -source 1.5

I build and run my Java Apache Camel code with the command 我使用以下命令构建并运行Java Apache Camel代码

mvn clean compile camel:run

This command has always worked for me, however when I have code that uses diamond operator I get an error. 该命令一直对我有用,但是当我有使用Diamond运算符的代码时,会出现错误。

My diamond operator: 我的钻石操作员:

private List<RestPropertyDefinition> restProperties = new ArrayList<>();

My error: 我的错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project camel-rest-example: Compilation failure
[ERROR] /home/sindre/IdeaProjects/training/camelrestexample/src/main/java/com/test/EmployeeRoute.java:[21,73] diamond operator is not supported in -source 1.5
[ERROR]   (use -source 7 or higher to enable diamond operator)

My POM File: 我的POM文件:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.test</groupId>
    <artifactId>camel-rest-example</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.apache.camel/camel-core -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.20.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.camel/camel-spring -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring</artifactId>
            <version>2.20.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>spi-annotations</artifactId>
            <version>2.20.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.camel/camel-jms -->
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jms</artifactId>
            <version>2.20.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-http4</artifactId>
            <version>2.20.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-quartz</artifactId>
            <version>2.20.0</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/org.apache.activemq/activemq-all -->
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-all</artifactId>
            <version>5.15.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.25</version>
            <scope>test</scope>
        </dependency>


    </dependencies>


    <build>
        <plugins>
            <!-- Allows the routes to be run via 'mvn camel:run' -->
            <plugin>
                <groupId>org.apache.camel</groupId>
                <artifactId>camel-maven-plugin</artifactId>
                <version>2.20.0</version>
            </plugin>
        </plugins>
    </build>
</project>

I am using Java 8, on Ubunut 18.04 with IntelliJ IDEA. 我在带有IntelliJ IDEA的Ubunut 18.04上使用Java 8。 It looks like IntelliJ believes that I am using Java 5? 看起来IntelliJ认为我正在使用Java 5? But I only have Java 8 installed on my machine 但是我的机器上只安装了Java 8

The compiler seems to assume source code level 1.5 by default. 默认情况下,编译器似乎假定源代码级别为1.5。

Tell the compiler the explicit versions like this using the pom: 使用pom告诉编译器这样的显式版本:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>2.5.1</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
      </configuration>
    </plugin>

This issue is because by default the Java Compiler is configured to use Java 1.5 for maximum compatibility, you can explicitly override for maven's compiler plugin by changing your configuration for the compiler plugin in your project pom.xml's plugins tag by adding the following entry 此问题是因为默认情况下,Java编译器配置为使用Java 1.5以获得最大兼容性,您可以通过添加以下条目来更改项目pom.xml的plugins标记中的编译器插件配置,从而显式覆盖maven的编译器插件。

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
</plugin>

You can find further documentation on the usage of the Maven Compiler Plugin here 您可以在此处找到有关Maven编译器插件用法的更多文档。

暂无
暂无

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

相关问题 -source 1.5 不支持菱形运算符 - diamond operator is not supported in -source 1.5 错误:-source1.5不支持菱形运算符 - error: diamond operator is not supported in -source1.5 为什么我得到错误 diamond operator is not supported in -source 1.5 in Java? - Why i get error diamond operator is not supported in -source 1.5 in Java? Visual Studio 2012 + Ant:-source 1.5中不支持Diamond运算符 - Visual Studio 2012 + Ant: diamond operator is not supported in -source 1.5 NetBeans:-source 1.5不支持菱形运算符(使用-source 7或更高版本启用菱形运算符) - NetBeans : diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator) 通过Maven错误进行议程代码编译:AgendaSample1Impl.java:[47,81]错误:-source 1.5中不支持Diamond运算符 - Agenda code compilation via maven error: AgendaSample1Impl.java:[47,81] error: diamond operator is not supported in -source 1.5 行家。 -source 1.5 不支持 lambda 表达式 - maven. lambda expressions are not supported in -source 1.5 为什么 Maven 会生成此错误:“...在 -source 1.5 中不受支持”? - Why is Maven generating this error: “…is not supported in -source 1.5”? 错误:(24,46)错误:-source 1.6不支持Diamond运算符(使用-source 7或更高版本来启用Diamond运算符) - Error:(24, 46) error: diamond operator is not supported in -source 1.6 (use -source 7 or higher to enable diamond operator) 源1.6不支持Java Combo Box Diamond运算符 - Java Combo Box Diamond Operator not supported in source 1.6
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM