views:

321

answers:

4

I have been trying to use Google Guice in eclipse plug-in development. I have imported Guice jar as another plug-in project. But somehow Guice is unable to inject dependency.

Any ideas???

This is the error message

com.google.inject.ConfigurationException: Guice configuration errors:

1) No implementation for java.util.List<java.lang.String> was bound.
  while locating java.util.List<java.lang.String>
    for parameter 1 at com.checker.extension.provider.util.PluginUtils.<init>(Unknown Source)
  while locating com.checker.extension.provider.util.PluginUtils

1 error

EDIT1

One thing which I would like to mention is the configuration works correctly when I use normal Java application but it don't when I use plug-in project

EDIT2 Below is the code which I am using

@Override
    protected void configure() {

        bind(List.class).toInstance(DIObjects.buildFolderNames);
    }

Here DIObjects.buildFolderNames is the static field which I need to inject. Defination of DIObjects.buildFolderNames is as follows.

public static List<String> buildFolderNames;

and I have initialized this field.

Is the problem is because of different classloaders of eclipse and Guice ???

A: 

Have you done something like this:

bind(List.class).to(ArrayList.class);

in your class that sets up your binings? Because List is just an Interface, so guice don't know what implementation to pick.

Alexander Kjäll
this sounds like a sensible answer. would the downvoter care to comment?
seanizer
The same answer has been repeated in both the answers posted earlier.. The Main question is how to integrate Guice in eclipse plug-in development env.
VinAy
+2  A: 

Looks like a configuration / annotation problem to me (at first sight). According to this article you have to annotate List to specify what kind of list you want to inject.

If the binding is correct in your code, make sure, that the packages that include the binding / the annotation classes are properly exported and properly declared in the plugin configuration. Maybe Guice just can't see the bindings.

Andreas_D
+7  A: 

You need to use a TypeLiteral to perform such a binding, for example:

bind(new TypeLiteral<List<String>>(){}).toInstance(new ArrayList<String>());

More info regarding bindings is available here.

gpampara
+1  A: 

Works for me. But I did something different - I went to the SpringSource Enterprise Bundle Repository and downloaded their Guice 2.0 bundle and its sole dependency, the AOP Alliance API 1.0.0 bundle. Then I added a dependency from my plugin to the Guice bundle. I created a static member variable like yours, initialized to a short list of strings, and bound it to List; then, in a TableViewer, created a content provider that gets the injector and calls getInstance(List.class), converting the return value to an array and returning it. The result: my strings visible in the table.

Here are links to the pages for the two bundles. On each page are links to the binary and source jars. Get either; import them into your workspace; add a dependency from your bundle to the Guice bundle; that ought to do it.

http://www.springsource.com/repository/app/bundle/version/detail?name=com.springsource.com.google.inject&amp;version=2.0.0&amp;searchType=bundlesByName&amp;searchQuery=guice

http://www.springsource.com/repository/app/bundle/version/detail?name=com.springsource.org.aopalliance&amp;version=1.0.0

Ladlestein
Did this solve your problem? I notice the bounty has elapsed without being awarded.
Ladlestein