简体   繁体   English

如何将番石榴添加到 Eclipse 项目中

[英]How to add Guava to Eclipse project

Eclipse Helios 3.6日食太阳神 3.6
Windows XP SP3视窗 XP SP3

I have used Eclipse to download the guava SDK by doing:我已经使用 Eclipse 通过执行以下操作来下载番石榴 SDK:
1) In Eclipse go to Help > Install New Software... 1) 在 Eclipse 中,转到帮助 > 安装新软件...
2) In the " Work with: " text box I used the following URL 2) 在“ Work with: ”文本框中,我使用了以下 URL

http://svn.codespot.com/a/eclipselabs.org/guava-bundle/trunk/repository/ 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. 3) 它找到了 Guava: Google Core Libraries for Java 1.5 Runtime 和 SDK,所以我对每条消息都点击了“确定”,它们似乎安装得很好。

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现在我想在我的代码中使用它(对于 Android 应用程序)我正在尝试将导入添加到我的一个类文件中

import com.google.common.collect.MapMaker;

I get a compile error message我收到一条编译错误消息

The import com.google cannot be resolved导入 com.google 无法解析

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.我一直在查看项目属性,我有一种感觉,我需要向Java Build Path > Libraries添加一个条目,但我不知道要添加什么。

As far as i know Google Guava is not an Eclipse Plugin.据我所知, Google Guava不是 Eclipse 插件。 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要将 lib 添加到 Eclipse 构建路径,只需右键单击您的项目 -> 构建路径 -> 配置构建路径 -> 库选项卡 -> 添加外部 jar -> 找到guava-r07.jar -> OK/OPEN

Just a little update here for everyone reading this in 2014. By now, there is an eclipse plugin for guava.在这里为 2014 年阅读本文的每个人做一点更新。现在,有一个适用于 guava 的 eclipse 插件。 It's part of the orbit project.这是轨道项目的一部分。 A collection of useful third party libraries.一组有用的第三方库。

You can find the latest version here .您可以在此处找到最新版本。

Figured it out, you just need to add the path to the location of the SDK as a Link Source.想通了,你只需要添加SDK位置的路径作为链接源。

1) Right click project and choose Properties > Source > Link Source... 1)右键单击项目并选择属性>源>链接源...
2) Browse to the location that eclipse downloaded the SDK to which on my computer was 2)浏览到eclipse下载我电脑上的SDK的位置

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

For everyone reading this in 2016... download Guava from this link对于在 2016 年阅读本文的每个人...从此链接下载番石榴

and do the steps as @Schildmeijer noted...并按照@Schildmeijer 指出的步骤执行...

To add a library to the build path, open eclipse right click in your project > select Properties.要将库添加到构建路径,请在您的项目中右键单击 eclipse > 选择 Properties。 On the left pane, select java build path.在左侧窗格中,选择 java 构建路径。 Pick the Libraries' tab and click "Add external Jar" (or "Add Jars" if it's inside your project's code)选择库的选项卡,然后单击“添加外部 Jar”(如果它在您的项目代码中,则单击“添加 Jar”)

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)无论如何,我不确定 guava 是否准备好与 android 一起使用(因为 android 使用了精简的 java 版本,适合轻量级设备)

看看另一个 SO 线程: 使用 Guava 的基础知识

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

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