简体   繁体   English

如何同时为Java和GWT项目共享EventBus?

[英]How can I share an EventBus for a Java and a GWT project at the same time?

I have a java project which uses the Guava EventBus . 我有一个使用Guava EventBus的Java项目。 Now I want to use the code from this project to work with GWT without rewriting it. 现在,我想使用该项目中的代码来与GWT一起使用,而无需重写它。 I know that GWT has its own EventBus but I cannot change the import in my Java project because this would break the Java project. 我知道GWT有自己的EventBus,但是我无法更改Java项目中的导入,因为这会破坏Java项目。

In my GWT project I included the guava and gwt-guava jars. 在我的GWT项目中,我加入了番石榴和gwt-guava罐子。 I also included: 我还包括:

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

in my gwt.xml file. 在我的gwt.xml文件中。 Guava worked at least for other classes (eg, Strings) in GWT project. 番石榴至少在GWT项目中为其他类(例如,字符串)工作。

I want to use Guava's EventBus instead of the one provided by GWT. 我想使用Guava的EventBus,而不是GWT提供的EventBus。 I need this because my Java project will not work with that GWT EventBus. 我需要这样做,因为我的Java项目无法与该GWT EventBus一起使用。 The problem is that the GWT project uses the GWT EventBus and the Java Project uses the Guava EventBus. 问题是GWT项目使用GWT EventBus,而Java项目使用Guava EventBus。 How do I get these things together? 如何将这些东西放在一起? It would b great if I could replace the Guava EventBus from the Java project in my GWT project somehow. 如果能以某种方式替换GWT项目中Java项目中的Guava EventBus,那就太好了。

How can How can I use Guava EventBus with GWT? 如何将Guava EventBus与GWT一起使用? Is there a way to use it without changing the dependencies in the other Java project? 有没有一种方法可以使用它而不更改其他Java项目中的依赖关系?

Guava's EventBus isn't available in GWT client code. Guava的EventBus在GWT客户端代码中不可用。 (You can tell because it doesn't have the @GwtCompatible annotation .) (您可以知道,因为它没有@GwtCompatible注释 。)

Sometimes a class that's not available under GWT can be made available. 有时可以使GWT下不可用的类可用。 EventBus , though, uses Java reflection, which is mostly unavailable under GWT, so it can't be made available. 但是, EventBus使用Java反射,而Java反射在GWT下几乎不可用,因此无法使其可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM