我使用命令
构建并运行我的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>
我在Ubunut 18.04上使用Java 8,使用IntelliJ IDEA。看起来IntelliJ认为我使用的是Java 5?但我只在我的机器上安装了Java 8
答案 0 :(得分:3)
编译器似乎默认假设源代码级别为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>
答案 1 :(得分:3)
此问题是因为默认情况下Java编译器配置为使用Java 1.5以实现最大兼容性,您可以通过更改项目pom.xml中编译器插件的配置来显式覆盖maven的编译器插件&#39 ; s plugins
标记,添加以下条目
<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>
您可以找到有关Maven编译器插件here
用法的更多文档