【问题标题】:Error when trying to use Guava FluentIterable with GWT尝试将 Guava FluentIterable 与 GWT 一起使用时出错
【发布时间】:2012-06-29 07:50:42
【问题描述】:

我正在尝试将 Guava 12.0 的 FluentIterable 与 GWT 2.0.3 一起使用,如下所示:

import com.google.common.collect.FluentIterable;

class FooPresenter {
   // snip

   private List<NullSafeCheckBox> asCheckboxes() {
      return FluentIterable.from(getDisplay().getMetricInputs())
         .transform(new Function<HasValueChangeHandlers<Boolean>, NullSafeCheckBox>() {
            @Override
            public NullSafeCheckBox apply(@Nullable HasValueChangeHandlers<Boolean> checkbox) {
               return (NullSafeCheckBox) checkbox;
            }
         })
         .toImmutableList();
   }
}

但是,当我在开发模式下运行 GWT 时,尝试加载第一个模块时出现以下错误:

DEBUG: Validating newly compiled units
  ERROR: Errors in 'jar:file:/home/josh/.m2/repository/com/google/guava/guava-gwt/12.0/guava-gwt-12.0.jar!/com/google/common/math/super/com/google/common/math/LongMath.java'
    ERROR: Line 23: The import java.math cannot be resolved

我的 pom.xml 看起来像这样:

  <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>12.0</version>
  </dependency>
  <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava-gwt</artifactId>
      <version>12.0</version>
  </dependency>

而我的 Application.gwt.xml 像这样吸收 Guava:

<!-- Guava -->
<inherits name="com.google.common.collect.Collect"/>

更新

按照Arcadian's answer 中的建议,我将 gwt-math 添加到我的 pom.xml 和我的 Application.gwt.xml:

  <!-- Guava -->
  <inherits name="com.google.common.collect.Collect"/>
  <inherits name="com.googlecode.gwt.math.Math" />

现在运行托管模式时出现此错误:

DEBUG: Validating newly compiled units
  WARN: Warnings in 'jar:file:/home/josh/.m2/repository/videoplaza-third-party/gwt-incubator/20100204-r1747/gwt-incubator-20100204-r1747.jar!/com/google/gwt/widgetideas/client/impl/GlassPanelImpl.java'
    WARN: Line 30: Referencing deprecated class 'com.google.gwt.user.client.impl.DocumentRootImpl'
    WARN: Line 38: Referencing deprecated class 'com.google.gwt.user.client.impl.DocumentRootImpl'
  ERROR: Errors in 'jar:file:/home/josh/.m2/repository/com/google/guava/guava-gwt/12.0/guava-gwt-12.0.jar!/com/google/common/primitives/UnsignedLong.java'
    ERROR: Line 77: The method bitLength() is undefined for the type BigInteger
    ERROR: Line 79: The method longValue() is undefined for the type BigInteger
    ERROR: Line 200: The method valueOf(long) is undefined for the type BigInteger
    ERROR: Line 202: The method setBit(int) is undefined for the type BigInteger

【问题讨论】:

    标签: java gwt guava


    【解决方案1】:

    您可以尝试添加gwt-java-math 项目作为依赖项。正如他们的维基上所说,

    这个库正在合并到 GWT 中! 目前它在 GWT 中继上。

    它可能会在即将发布的 v2.5 中提供。

    【讨论】:

    • 谢谢!至少,这让我遇到了下一个错误。 :) 查看我原来问题的更新。
    • 我认为您必须删除非 gwt guava 依赖项。它可能会限制可用 guava 类的数量,但要确保它们是 GWT 化的。比如说,在 guava-java 和 guava-gwt 之间选择,同时使用可能会混淆类加载器
    • This answer 表示您的 POM 中需要两个 Guava 依赖,事实上,当我省略非 GWT Guava 时,它对我不起作用。
    【解决方案2】:

    仅供参考,在我看来 java.math 应该在当前版本的 GWT 中可用,尽管可能不在 2.0.3 中。例如,请参阅the JRE emulation reference for GWT 2.2,这可能是它可用的第一个版本。

    我不知道结合 gwt-java-math 会发生什么;可能 Guava 本身需要声明对其模块的依赖才能使其工作?

    我们确实需要更好地确定和宣传 Guava 需要哪个版本的 GWT,包括针对 Guava(而不仅仅是我们的内部版本)运行我们的 GWT 测试来验证这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-12
      • 2019-08-24
      • 2012-10-30
      • 2021-04-02
      • 1970-01-01
      相关资源
      最近更新 更多