【问题标题】:error compiling java -use source 5编译 java -use source 5 时出错
【发布时间】:2014-10-14 01:16:50
【问题描述】:

如果这是一个愚蠢的问题,请原谅我,但我正在尝试编译我在 http://thisdataguy.com/2014/02/07/how-to-build-a-full-flume-interceptor-by-a-non-java-developer/ 找到的一些 java 代码

我对 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] ------------------------------------------------------------------------

【问题讨论】:

  • annotations are not supported in -source 1.3generics are not supported in -source 1.3for-each loops are not supported in -source 1.3。有你的问题,这些不支持。 use -source 5 or higher
  • 我该怎么做呢?就像我在原帖中所说的那样,我对 java 作为一种编程语言非常陌生。
  • 也许您使用的是过时的 JDK 或 maven 版本?
  • 下载并尝试使用更新的 java 版本 jdk6、7 或 8 和 Maven 2.x 或 3.x。
  • 请至少使用 Maven 3.X 而不是 Maven 2.X anymore

标签: java maven maven-2 maven-assembly-plugin flume


【解决方案1】:

显然,Maven 的编译器插件并不关心您实际使用的 Java 版本。错误信息提示您在pom.xml 中设置一些配置:

【讨论】:

    【解决方案2】:

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

    [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 或更高版本来启用 for-each 循环)

    您可能使用的是过时版本的 JDK(6 或更高版本)和/或 Maven(3.x 或更高版本)。更新到最新的 JDK 和 Maven 版本,错误应该消失了。

    但是,正如构建报告末尾的 INFO 部分所述,for more information, run Maven with the -e switch。这将有助于您在将来调试问题。

    【讨论】:

    • 我正在使用 java6 (open-jdk6) 和 maven 2
    • @KevinWincott 抱歉,3 岁或以上,而不是 2 岁或以上。
    • 尽快更新到 Maven 3...cause Maven 2 is EoL.
    猜你喜欢
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    • 2014-06-17
    • 2021-05-17
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多