我有一个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
我的其他代码中没有这些错误,包括其他一些外部罐子而不是番石榴!
答案 0 :(得分:3)
我假设你在谈论作为GCC编译器套件一部分的GCJ Java编译器。
我担心,GCJ依赖于GNU Classpath库,而这些库并没有完全覆盖Java 5类库。在Sun开源Java 6之后,类路径开发工作停滞不前。
您尝试编译的代码取决于Java 8 API。它们从未在Classpath中实现。这是你得到的编译错误的根本原因。
GCJ工具链现在已经死了。正如Wikipedia page所说:
截至2015年,GCJ没有宣布新的开发项目,产品处于维护模式。 GCJ于2016年9月30日从海湾合作委员会主干中移除。通过发布GCC 7.1(不包含GCC 7.1)宣布取消。 GCJ仍然是GCC 6的一部分。
如果您正在寻找可行的Java AOT(提前)编译器,请考虑: