java - Apache Maven:-source 1.5 中不支持 Diamond 运算符
问题描述
我使用以下命令构建并运行我的 Java Apache Camel 代码
mvn clean compile camel:run
这个命令一直对我有用,但是当我有使用菱形运算符的代码时,我得到一个错误。
我的钻石运营商:
private List<RestPropertyDefinition> restProperties = new ArrayList<>();
我的错误:
[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)
我的 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>
我在带有 IntelliJ IDEA 的 Ubunut 18.04 上使用 Java 8。看起来 IntelliJ 认为我使用的是 Java 5?但我的机器上只安装了 Java 8
解决方案
编译器似乎默认假定源代码级别为 1.5。
使用 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>
推荐阅读
- android - 错误:无法解决:com.google.firebase:firebase-appindexing
- bash - 变量替换
- java - 如何在java中查找读取文件中特定字符的数量
- sql-server - 将包含以科学计数法表示的数字的 varchar 转换为十进制时出错
- ruby-on-rails - 如何使用 Chef 安装 redmine
- php - JSON 返回过多信息
- python - 使用布尔选择选择一个数据框,然后提取对应于某一列的值
- google-cloud-build - 无法从云构建中提取 BRANCH_NAME
- python - 如何从在 Python 中执行的 R 脚本返回多个对象
- api - 使用 Web Api 连接 Windows 服务?