导入 Guava 源时无法解析导入 javax.inject
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18616259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The import javax.inject cannot be resolved while import Guava source
提问by midnite
i would like to use the Guava's TypeToken, then i downloaded the Guava Release 14.0 from here. (i assume 14.0 is more stable than 15.0 rc.)
我想使用Guava 的 TypeToken,然后我从这里下载了 Guava Release 14.0 。(我假设 14.0 比 15.0 rc 更稳定。)
guava-14.0.1-sources.jar (Source)
http://search.maven.org/remotecontent?filepath=com/google/guava/guava/14.0.1/guava-14.0.1-sources.jar
Unzip the downloaded guava-14.0.1-sources.jarinto a folder.
将下载的解压guava-14.0.1-sources.jar到一个文件夹中。
Then i created a Java 1.7 project in Eclipse.
然后我在 Eclipse 中创建了一个 Java 1.7 项目。
And linked the source in Eclipse by Java Build Path -> Source -> Link Source....
并通过Java Build Path -> Source -> Link Source....
Note i am notusing (and don't know how to use) any build systems like Maven.
请注意,我没有使用(也不知道如何使用)任何像 Maven 这样的构建系统。
First i got a problem of The import javax.annotation.Nullable cannot be resolved. But this is solved already.i followed the thread hereto download jsr305-2.0.1.jarfrom this page. (i assume 2.0.1 is the most latest release.)
首先我遇到了一个问题The import javax.annotation.Nullable cannot be resolved。但这已经解决了。我按照这里的线程从这个页面下载jsr305-2.0.1.jar。(我假设 2.0.1 是最新版本。)
Secondly i got the rt.jar access restrictionproblem like this one. This is also solvedby simply re-add the JRE System Library, like the answer there.
其次我得到了rt.jar access restriction类似的问题这一个。这也可以通过简单地重新添加 JRE 系统库来解决,就像那里的答案一样。
Now i got this problem that i cannot solve, and there are no solutions from the web.
现在我遇到了这个我无法解决的问题,而且网上也没有解决方案。
In package com.google.common.util.concurrentclass ServiceManager, there are a few compile errors.
在包com.google.common.util.concurrent类中ServiceManager,有一些编译错误。
import javax.inject.Inject; // The import javax.inject cannot be resolved
import javax.inject.Singleton; // The import javax.inject cannot be resolved
To my understanding, this is a similar problem with the "first problem". But the jsr305-2.0.1.jarincludes javax.annotation.Nullable, but it does not include javax.inject.*. What i need is a Java library that includes javax.inject.*.
据我了解,这是与“第一个问题”类似的问题。但是jsr305-2.0.1.jar包括javax.annotation.Nullable,但它不包括javax.inject.*。我需要的是一个包含javax.inject.*.
Could you please help? Thanks a lot!
能否请你帮忙?非常感谢!
采纳答案by chrylis -cautiouslyoptimistic-
The javax.injectpackage is provided in Java EE. If you're needing to use it in Java SE for some reason, you can explicitly include a jar with the API interfaces in it. Maven Centralhas a link to an implementation (javax.inject:javax.inject). Actually using Maven will make life simpler, but you can just download the jarfile and include it manually.
该javax.inject包在 Java EE 中提供。如果您出于某种原因需要在 Java SE 中使用它,您可以显式地包含一个带有 APIinterface的jar 。Maven Central有一个实现的链接 ( javax.inject:javax.inject)。实际上使用 Maven 会使生活更简单,但您只需下载jar文件并手动包含它。

