编译java时出错-使用源代码5

yshpjwxd  于 2021-06-04  发布在  Flume
关注(0)|答案(2)|浏览(409)

请原谅我,如果这是一个愚蠢的问题,但我正在试图编译一些java代码,我发现在http://thisdataguy.com/2014/02/07/how-to-build-a-full-flume-interceptor-by-a-non-java-developer/
我对java编程非常陌生,当我运行代码时,会发现错误:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - org.apache.flume:eventTweaker:jar:1.0
[INFO]    task-segment: [clean, package]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting file set: /home/kwincott/jars/tweaker/target (included: [**], excluded:    [])
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/kwincott/jars/tweaker/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 1 source file to /home/kwincott/jars/tweaker/target/classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure

/home/kwincott/jars/tweaker/src/main/java/com/example/flume/interceptors   /eventTweaker.java:[18,3] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
@Override

/home/kwincott/jars/tweaker/src/main/java/com/example/flume/interceptors/eventTweaker.java:[24,7] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
Map<String, String> headers = event.getHeaders();

/home/kwincott/jars/tweaker/src/main/java/com/example/flume/interceptors/eventTweaker.java:[46,20] for-each loops are not supported in -source 1.3
(use -source 5 or higher to enable for-each loops)
for (Event event:events) {

[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Wed Aug 20 16:26:17 BST 2014
[INFO] Final Memory: 19M/303M
[INFO] ------------------------------------------------------------------------
wvt8vs2t

wvt8vs2t1#

构建失败报告几乎说明了一切:

[18,3] annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
@Override

[24,7] generics are not supported in -source 1.3
(use -source 5 or higher to enable generics)
Map<String, String> headers = event.getHeaders();

[46,20] for-each loops are not supported in -source 1.3
(use -source 5 or higher to enable for-each loops)
for (Event event:events) {

(使用-source 5或更高版本为每个循环启用)
您可能正在使用jdk(6或更高版本)和/或maven(3.x或更高版本)的过时版本。更新到最新的jdk和maven版本,错误应该消失了。
但是,正如构建报告末尾的信息部分所说, for more information, run Maven with the -e switch . 这将帮助您在将来调试问题。

mepcadol

mepcadol2#

显然,maven的编译器插件并不关心您实际使用的java版本。错误消息提示您在系统中设置某些配置 pom.xml :
maven编译器插件文档
还有帮助:使用javac和javax.tools.javacompiler有什么区别?

相关问题