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

gcj Error - cannot find file for class java.util.function.Predicate

我有一个 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!

我假设您在谈论 GCJ Java 编译器,它是 GCC 编译器套件的一部分。

恐怕 GCJ 依赖于 GNU Classpath 个库,而这些库没有实现对 Java 5 class 个库的完全覆盖。 Sun 开源 Java 6.

后,类路径开发工作停止了

您尝试编译的代码依赖于 Java 8 个 API。它们从未在类路径中实现。这就是您遇到的编译错误的根本原因。

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(提前)编译器,请考虑: