Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The import javax.inject cannot be resolved while import Guava source

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-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.jar into a folder.

Then i created a Java 1.7 project in Eclipse.

And linked the source in Eclipse by Java Build Path -> Source -> Link Source....

Note i am not using (and don't know how to use) any build systems like Maven.

First i got a problem of The import javax.annotation.Nullable cannot be resolved. But this is solved already. i followed the thread here to download jsr305-2.0.1.jar from this page. (i assume 2.0.1 is the most latest release.)

Secondly i got the rt.jar access restriction problem like this one. This is also solved by simply re-add the JRE System Library, like the answer there.

Now i got this problem that i cannot solve, and there are no solutions from the web.

In package com.google.common.util.concurrent class ServiceManager, there are a few compile errors.

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.jar includes javax.annotation.Nullable, but it does not include javax.inject.*. What i need is a Java library that includes javax.inject.*.

Could you please help? Thanks a lot!

like image 619
midnite Avatar asked Nov 30 '22 20:11

midnite


2 Answers

The javax.inject package 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 Central has a link to an implementation (javax.inject:javax.inject). Actually using Maven will make life simpler, but you can just download the jar file and include it manually.

like image 75
chrylis -cautiouslyoptimistic- Avatar answered Dec 04 '22 07:12

chrylis -cautiouslyoptimistic-


You can get the javax.inject jar here. You don't need to use maven, just download the .jar.

like image 42
Sotirios Delimanolis Avatar answered Dec 04 '22 06:12

Sotirios Delimanolis