Results 1 to 3 of 3

Thread: [Java] Trouble Installing Google Guice

  1. #1
    Join Date
    Aug 2006
    Beans
    34

    [Java] Trouble Installing Google Guice

    Hi,

    I'm trying to play around with Google Guice and I can't seem to get it set up properly.

    I have installed it as follows:
    Code:
    sudo apt-get install libguice-java libguice-java-doc
    Following this tutorial, I am trying to compile this simple program:

    Code:
    import com.google.inject.*;
    
    public class GumRunner {
    
       public static void main(String args[]){
    
          Injector injector = Guice.createInjector();
         System.out.println(injector);
    
      }
    }
    and I get the following error when compiling:
    Code:
    $ javac GumRunner.java 
    GumRunner.java:1: error: package com.google.inject does not exist
    import com.google.inject.*;
    ^
    GumRunner.java:7: error: cannot find symbol
          Injector injector = Guice.createInjector();
          ^
      symbol:   class Injector
      location: class GumRunner
    GumRunner.java:7: error: cannot find symbol
          Injector injector = Guice.createInjector();
                              ^
      symbol:   variable Guice
      location: class GumRunner
    3 errors
    Any ideas as to why this isn't working? I'm a newbie with Java, so please be gentle!

  2. #2
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,035
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: [Java] Trouble Installing Google Guice

    I don't know Guice, but that first error indicates that whatever .jar(s) are needed are not on the default classpath.

    If you try
    Code:
    javac -verbose GumRunner.java
    it should tell you where it's looking.

    The tutorial you link to compiles with a classpath specified, but that's for Windows.

    I think that you'll need something like:
    Code:
    javac -classpath /usr/share/java/guice.jar GumRunner.java

  3. #3
    Join Date
    Aug 2006
    Beans
    34

    Re: [Java] Trouble Installing Google Guice

    Hi Spjackson,

    Thanks, this really helped. Just had to add . and /usr/share/java/javax.inject.jar to the classpath, i.e.

    Code:
    javac -cp '.:/usr/share/java/guice-3.0.jar:/usr/share/java/javax.inject.jar' GumRunner.java
    Thanks again

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •