GWT-GIN rebinding error or Google JAR hell?

164 views
Skip to first unread message

zharvey

unread,
Nov 17, 2012, 2:47:42 PM11/17/12
to googl...@googlegroups.com
I am trying to use GIN with a GWT app for the first time and am running into what I *believe* is a JAR hell (versioning) issue. I have the following project directory structure:

    MyApp/
        com.myapp
            MyApp.gwt.xml
        com.myapp.client
            MyAppModule
            MyAppActivityMapper
        com.myapp.client.plumbing.di
            IMyAppGinjector
            MyAppModuleInjector
        Referenced Libraries/ (this is Eclipse Indigo and these are on project buildpath)
            aopalliance.jar
            gin-2.0.jar
            guice-3.0.jar
            guice-assistedinject-3.0.jar
            javax.inject.jar

The essential code:

    <!-- MyApp.gwt.xml -->
    <module rename-to="myAppModule">
        <inherits name="com.google.gwt.user.User"/>
        <inherits name="com.google.gwt.inject.Inject"/>
        <inherits name="com.google.gwt.activity.Activity"/>

        <entry-point class="com.myapp.client.MyAppModule"/>

        <!-- Configure GWT sourcepath. -->
        <source path='client'/>
        <source path='shared'/>
    </module>

    public class MyAppModule implements EntryPoint {
        private final IMyAppGinjector injector = GWT.create(IMyAppGinjector.class);
        private ActivityManager baseManager;

        @Override
        public void onModuleLoad() {
            baseManager = injector.getBaseManager();

            // Lots of other stuff.
        }
    }

    @GinModules(MyAppModuleInjector.class)
    public interface IMyAppGinjector extends Ginjector {
        public ActivityManager getBaseManager();
    }

    public class MyAppModuleInjector extends AbstractGinModule {
        @Override
        protected void configure() {
            // Binding for simple things.
            bind(EventBus.class).to(SimpleEventBus.class);

            // ...etc.
        }

        @Provides
        @Singleton
        public ActivityManager getBaseManager() {
            ActivityMapper myMapper = new MyAppActivityMapper();

            return new ActivityManager(myMapper);
        }
    }

My understanding is that annotating the `MyAppModuleInjector#getBaseManager` with the `@Provides` methods allows GIN to automatically select that method as the provider when my `MyAppModule#onModuleLoad()` calls `baseManager = injector.getBaseManager()`. **This may be the cause of my error**, but I have also found evidence that I may have versions of GWT, GIN and Guice that don't play nicely together.

When I run this code locally in Eclipse, I get the following error in the *Development Mode* console:

    09:29:44.417 [ERROR] [myAppModule] Generator 'com.google.gwt.inject.rebind.GinjectorGenerator' threw an exception while rebinding 'com.myapp.client.plumbing.di.IMyAppModuleGinjector'
    com.google.inject.CreationException: Guice creation errors:
    1) No implementation for javax.inject.Provider<com.google.gwt.inject.rebind.GinjectorBindings> was bound.
    while locating javax.inject.Provider<com.google.gwt.inject.rebind.GinjectorBindings>
    for parameter 4 at com.google.gwt.inject.rebind.GinjectorBindings.<init>(GinjectorBindings.java:196)
    at com.google.gwt.inject.rebind.GinjectorGeneratorModule.configure(GinjectorGeneratorModule.java:75)
    1 error
    at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:354)
    at com.google.inject.InjectorBuilder.initializeStatically(InjectorBuilder.java:152)
    at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:105)
    at com.google.inject.Guice.createInjector(Guice.java:92)
    at com.google.inject.Guice.createInjector(Guice.java:69)
    at com.google.inject.Guice.createInjector(Guice.java:59)
    ...I am omitting the rest of this lengthy stack trace for brevity, but it is getting thrown when I
        am creating my IMyAppGinjector instance at the top of MyAppModule

I pasted this exception into Google and only found a few other instances of this occurring. The best I found was [this forum post](http://www.mail-archive.com/google-we...@googlegroups.com/msg59270.html) where the user discovered that he/she had a GIN/Guice combo that was bad. He/she changed versions of those libraries and it looks like it resolved their problem.

I am using:
  • GWT - 2.4
  • GIN - 2.0
  • Guice - 3.0
My only two guesses are:
  1.  I am not using the `@Provides` annotation (or its respective provider method) correctly, in which case, how should I use this?; or
  2.  I have, essentially, a Google JAR hell dilemma
Any ideas? Thanks in advance!

zharvey

unread,
Nov 21, 2012, 6:30:19 AM11/21/12
to googl...@googlegroups.com
This is a project that has zero community support behind it - I do not recommend GIN to any newcomers and instead recommend DIY-DI as the DI "framework" for GWT development, which so far is working very well for me. It's actually not a framework, more or less a set of very simple principles for lightweight, custom DI.
I pasted this exception into Google and only found a few other instances of this occurring. The best I found was [this forum post](http://www.mail-archive.com/google-web-toolkit@googlegroups.com/msg59270.html) where the user discovered that he/she had a GIN/Guice combo that was bad. He/she changed versions of those libraries and it looks like it resolved their problem.

Jens

unread,
Nov 21, 2012, 6:47:38 AM11/21/12
to googl...@googlegroups.com
Have you tried using com.google.inject.Provider instead of javax.inject.Provider ?

Also notice that using javax.inject.Inject introduces some constraints, see: 

Thomas Broyer

unread,
Nov 21, 2012, 9:28:30 AM11/21/12
to googl...@googlegroups.com


On Wednesday, November 21, 2012 12:47:38 PM UTC+1, Jens wrote:
Have you tried using com.google.inject.Provider instead of javax.inject.Provider ?

Jens, the error comes from the *internals* of the GWT generator. I can't understand what's going wrong here, particularly as I'm using GIN 2.0 with GWT 2.5 (not 2.4 though, but GIN has been built and tested against 2.4) with no problem. Main difference is I'm using Maven.

Goktug Gokdogan

unread,
Nov 21, 2012, 3:24:59 PM11/21/12
to googl...@googlegroups.com
I'm also using GIN via maven and it works pretty well for me. I agree that sometimes especially for newcomers there might some issues in the initial setup but after that it works pretty well.

And my best guess is, you might have trouble with including multiple versions of the same library.


--
You received this message because you are subscribed to the Google Groups "google-gin" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-gin/-/BDZVtxMqg2MJ.

To post to this group, send email to googl...@googlegroups.com.
To unsubscribe from this group, send email to google-gin+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-gin?hl=en.

Jens

unread,
Nov 21, 2012, 5:04:05 PM11/21/12
to googl...@googlegroups.com

On Wednesday, November 21, 2012 12:47:38 PM UTC+1, Jens wrote:
Have you tried using com.google.inject.Provider instead of javax.inject.Provider ?

Jens, the error comes from the *internals* of the GWT generator. I can't understand what's going wrong here, particularly as I'm using GIN 2.0 with GWT 2.5 (not 2.4 though, but GIN has been built and tested against 2.4) with no problem. Main difference is I'm using Maven.

Hmm I see, then I have no idea either.

I am also using GIN 2.0 (well actually a trunk version  r251, but its pretty much the 2.0 tag.), Guice 3 with GWT 2.4 as well as GWT 2.5 without problems and without Maven.

@zharvey: Have you double checked your classpath?

-- J.




Jens

unread,
Dec 27, 2012, 10:31:10 AM12/27/12
to googl...@googlegroups.com
Someone on the Google Web Toolkit group solved this issue by reordering the libraries on classpath, see:


Not sure if its really the correct solution but if it is maybe its possible to make GIN resistant against classpath orderings?


-- J.
Reply all
Reply to author
Forward
0 new messages