19

Eclipse Helios 3.6
Windows XP SP3

I have used Eclipse to download the guava SDK by doing:
1) In Eclipse go to Help > Install New Software...
2) In the "Work with:" text box I used the following URL

http://svn.codespot.com/a/eclipselabs.org/guava-bundle/trunk/repository/

3) It found the Guava: Google Core Libraries for Java 1.5 Runtime and SDK, so I clicked ok to each message and they seemed to install fine.

Now I want to use it in my code (for an Android app) I am trying to add an import to one of my class files

import com.google.common.collect.MapMaker;

I get a compile error message

The import com.google cannot be resolved

Is there any special step I need to perform in order add the library to my project?

I have been looking through the project properties, I've got a feeling I need to add an entry to Java Build Path > Libraries but I do not know what to add.

Martin Belcher - AtWrk
  • 4,579
  • 4
  • 33
  • 41

6 Answers6

32

As far as i know Google Guava is not an Eclipse Plugin. It's a third party library. To add a lib to the Eclipse build path simply right click on your project -> build path -> configure build path -> libraries tab -> add external jars -> locate guava-r07.jar -> OK/OPEN

Schildmeijer
  • 20,702
  • 12
  • 62
  • 79
  • Thanks, I've accepted this answer because it best points out that I was looking in the wrong place for how to add the SDK. This link was handy when I came to the add the guava-r07.jar file to my project. http://www.vogella.de/articles/Eclipse/article.html#classpath – Martin Belcher - AtWrk Jan 10 '11 at 17:03
4

Just a little update here for everyone reading this in 2014. By now, there is an eclipse plugin for guava. It's part of the orbit project. A collection of useful third party libraries.

You can find the latest version here.

Dave
  • 161
  • 9
4

Figured it out, you just need to add the path to the location of the SDK as a Link Source.

1) Right click project and choose Properties > Source > Link Source...
2) Browse to the location that eclipse downloaded the SDK to which on my computer was

C:\Program Files\eclipse\plugins\com.google.guava.source_1.7.0

Martin Belcher - AtWrk
  • 4,579
  • 4
  • 33
  • 41
  • Does not work either. This throws up problems when compiling the Guava classes it doesn't recognise @Nullable or @GuardedBy. I think for the time being I'll download the precompiled .JAR and add that to the project. Just seems a bit of a hacky way of doing it. – Martin Belcher - AtWrk Jan 10 '11 at 16:52
2

For everyone reading this in 2016... download Guava from this link

and do the steps as @Schildmeijer noted...

Mohamed Horani
  • 544
  • 3
  • 9
  • 23
0

To add a library to the build path, open eclipse right click in your project > select Properties. On the left pane, select java build path. Pick the Libraries' tab and click "Add external Jar" (or "Add Jars" if it's inside your project's code)

Anyway, I'm not sure if guava is prepared to be used with android (because android uses a striped down java version, good for lightweight devices)

Pedro Loureiro
  • 11,436
  • 2
  • 31
  • 37
0

Take a look at this other SO thread: The very basics for using Guava.

Community
  • 1
  • 1
jhurtado
  • 8,587
  • 1
  • 23
  • 34
  • Thanks I did read that but I wasn't sure it was the correct way to add it. I thought if I add it via Eclipse it will be able to automatically check for and download updates like it does for the Android SDK. – Martin Belcher - AtWrk Jan 10 '11 at 16:47