java - gcj错误-找不到类java.util.function.Predicate的文件

原文 标签 java compiler-errors guava machine-code gcj

我有一个Java代码,必须使用guava23.0.jar作为外部库。
更具体地说,我需要具有以下导入:

import com.google.common.base.Charsets;
import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnel;
import com.google.common.hash.PrimitiveSink;

我构建代码的jar文件,现在尝试使用gcj生成机器代码。
我测试了jar文件,它可以正常工作并提供输出。
但是,当尝试使用gcj编译并生成机器代码时,它给了我几个错误:
com/google/common/base/Predicate.java:0:0: error: cannot find file for class java.util.function.Predicate
com/google/common/base/Predicate.java: At top level:
com/google/common/base/Predicate.java:0:0: error: cannot find file for class java.util.function.Predicate
com/google/common/base/Predicate.java:0:0: error: cannot find file for class java.util.function.Predicate
com/google/common/base/Supplier.java: In class 'com.google.common.base.Absent':
com/google/common/base/Supplier.java: In method 'com.google.common.base.Absent.or(com.google.common.base.Supplier)':
In file included from com/google/common/base/Absent.java:60:0,
                 from com/google/common/annotations/VisibleForTesting.java:2,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/Supplier.java:0:0: error: cannot find file for class java.util.function.Supplier
In file included from com/google/common/annotations/VisibleForTesting.java:2:0,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/Absent.java:60:0: error: cannot find file for class java.util.function.Supplier
com/google/common/base/Absent.java:60:0: error: cannot find file for class java.util.function.Supplier
com/google/common/base/Absent.java:60:0: error: cannot find file for class java.util.function.Supplier
com/google/common/base/Function.java: At top level:
In file included from com/google/common/base/Ascii.java:636:0,
                 from com/google/common/base/AbstractIterator.java:89,
                 from com/google/common/base/AbstractIterator.java:35,
                 from com/google/common/base/AbstractIterator.java:60,
                 from com/google/common/base/Absent.java:27,
                 from com/google/common/annotations/VisibleForTesting.java:2,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/Function.java:0:0: error: cannot find file for class java.util.function.Function
In file included from com/google/common/base/Ascii.java:634:0,
                 from com/google/common/base/AbstractIterator.java:89,
                 from com/google/common/base/AbstractIterator.java:35,
                 from com/google/common/base/AbstractIterator.java:60,
                 from com/google/common/base/Absent.java:27,
                 from com/google/common/annotations/VisibleForTesting.java:2,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/CaseFormat.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/CaseFormat.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/CaseFormat.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/CaseFormat.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/CaseFormat.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/CaseFormat.java:0:0: error: cannot find file for class java.util.function.Function
In file included from com/google/common/base/Ascii.java:640:0,
                 from com/google/common/base/AbstractIterator.java:89,
                 from com/google/common/base/AbstractIterator.java:35,
                 from com/google/common/base/AbstractIterator.java:60,
                 from com/google/common/base/Absent.java:27,
                 from com/google/common/annotations/VisibleForTesting.java:2,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/Converter.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/Converter.java:0:0: error: cannot find file for class java.util.function.Function
com/google/common/base/CaseFormat.java: In class 'com.google.common.base.CaseFormat':
com/google/common/base/CaseFormat.java: In method 'com.google.common.base.CaseFormat.convert(com.google.common.base.CaseFormat,java.lang.String)':
In file included from com/google/common/base/CaseFormat.java:155:0,
                 from com/google/common/base/CaseFormat.java:101,
                 from com/google/common/base/CaseFormat.java:82,
                 from com/google/common/base/CaseFormat.java:74,
                 from com/google/common/base/CaseFormat.java:66,
                 from com/google/common/base/CaseFormat.java:47,
                 from com/google/common/base/Ascii.java:641,
                 from com/google/common/base/AbstractIterator.java:89,
                 from com/google/common/base/AbstractIterator.java:35,
                 from com/google/common/base/AbstractIterator.java:60,
                 from com/google/common/base/Absent.java:27,
                 from com/google/common/annotations/VisibleForTesting.java:2,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/CaseFormat.java:130:0: error: cannot find file for class java.util.function.Predicate
com/google/common/base/CaseFormat.java:130:0: error: cannot find file for class java.util.function.Predicate
com/google/common/base/CharMatcher.java: In class 'com.google.common.base.CharMatcher$And':
com/google/common/base/CharMatcher.java: In method 'negate()':
In file included from com/google/common/base/CharMatcher.java:616:0,
                 from com/google/common/base/CaseFormat.java:30,
                 from com/google/common/base/CaseFormat.java:155,
                 from com/google/common/base/CaseFormat.java:101,
                 from com/google/common/base/CaseFormat.java:82,
                 from com/google/common/base/CaseFormat.java:74,
                 from com/google/common/base/CaseFormat.java:66,
                 from com/google/common/base/CaseFormat.java:47,
                 from com/google/common/base/Ascii.java:641,
                 from com/google/common/base/AbstractIterator.java:89,
                 from com/google/common/base/AbstractIterator.java:35,
                 from com/google/common/base/AbstractIterator.java:60,
                 from com/google/common/base/Absent.java:27,
                 from com/google/common/annotations/VisibleForTesting.java:2,
                 from com/google/common/annotations/GwtIncompatible.java:1,
                 from com/google/common/annotations/GwtCompatible.java:1,
                 from com/google/common/annotations/Beta.java:1,
                 from bloomfilter/MultipleBloomFilterCheck.java:41,
                 from bloomfilter/MultipleBloomFilterCheck.java:100,
                 from bloomfilter/Main.java:25,
                 from <built-in>:3:
com/google/common/base/CharMatcher.java:1719:0: error: cannot find file for class java.util.function.Predicate
com/google/common/base/CharMatcher.java:1719: confused by earlier errors, bailing out

我的其他代码中没有这些错误,其中包括 Guava 以外的其他外部 jar !

最佳答案

我假设您正在谈论的是GCC编译器套件中的GCJ Java编译器。

恐怕GCJ依赖GNU Classpath库,而这些库并没有完全覆盖Java 5类库。 Sun开源Java 6之后,类路径开发工作停止了。

您尝试编译的代码取决于Java 8 API。它们从未在Classpath中实现。这是您得到编译错误的根本原因。

现在,GCJ工具链实际上已失效。正如Wikipedia page所说:

As of 2015, there were no new developments announced from GCJ and the product was in maintenance mode. GCJ was removed from the GCC trunk on September 30, 2016. Announcement of its removal was made with the release of the GCC 7.1, which does not contain it. GCJ remains part of GCC 6.



如果您正在寻找可行的Java AOT(提前)编译器,请考虑:
  • Java 9 experimental AOT compiler
  • Excelsior JET
  • IBM AOT compiler
  • 关于java - gcj错误-找不到类java.util.function.Predicate的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50101655/

    相关文章:

    java - 如何使嵌入式 Jpanel 转到 WEST

    scripting - 使用模拟事件BeginViewTarget制作等距相机

    java - 为什么不建议使用MapMaker.softKeys()?

    java - 细木工订购不正确?

    java - Java:连接Scala模块

    java - 如何在Kotlin中填充String []数组

    java - 建立入侵检测系统,但从何开始

    java - 有人可以告诉我在Java中设置此Robot类时我做错了什么吗?

    java - 如何修复Java :26: error: No suitable constructor found

    java - Guava copyOf嵌套集合