gpt4 book ai didi

Java 错误 - lambda 表达式在 -source 1.5 中不受支持(使用 -source 8 或更高版本来启用 lambda 表达式)

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:44:34 28 4
gpt4 key购买 nike

我正在尝试构建一个使用 lambda 表达式的 Kafka Streams 应用程序。

我的 maven 构建配置是 mvn clean install

当我执行 RunAs > Maven 构建时,出现以下错误:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/junaid/eMumba/StreamsExample/streams.examples/src/main/java/myapps/Pipe.java:[53,38] lambda expressions are not supported in -source 1.5
(use -source 8 or higher to enable lambda expressions)
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.265 s
[INFO] Finished at: 2018-02-24T14:50:04+05:00
[INFO] Final Memory: 11M/150M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project streams.examples: Compilation failure
[ERROR] /home/junaid/eMumba/StreamsExample/streams.examples/src/main/java/myapps/Pipe.java:[53,38] lambda expressions are not supported in -source 1.5
[ERROR] (use -source 8 or higher to enable lambda expressions)

Java 构建路径 中,我有 JRE 系统库 [JavaSE 1.8]

Preferences > Java > Installed JREs 我有 java-8-openjdk

这是我的pom.xml:

我在最后添加了 org.apache.maven.plugins: maven-compiler-plugin 依赖。

<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>streamsexamples</groupId>
<artifactId>streams.examples</artifactId>
<version>0.1</version>
<packaging>jar</packaging>

<name>Kafka Streams Quickstart :: Java</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kafka.version>1.0.0</kafka.version>
<slf4j.version>1.7.7</slf4j.version>
<log4j.version>1.2.17</log4j.version>
</properties>

<!-- Execute "mvn clean package -Pbuild-jar" to build a jar file out of
this project! -->

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>
myapps.Pipe
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<!-- Apache Kafka dependencies -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-streams</artifactId>
<version>${kafka.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</dependency>

</dependencies>
</project>

我该怎么做才能解决这个问题?

最佳答案

尝试将源版本和目标版本添加到您的 pom:

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

参见 https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

关于Java 错误 - lambda 表达式在 -source 1.5 中不受支持(使用 -source 8 或更高版本来启用 lambda 表达式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48961722/

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