问题
I'm trying to use Google Guice Injections in my Play 2.2.2 project. My build.sbt
file contains this:
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache,
"com.google.inject" % "guice" % "4.0-beta",
"ws.securesocial" %% "securesocial" % "2.1.4",
"postgresql" % "postgresql" % "9.1-901-1.jdbc4"
)
When running play dependencies
, I can see that the guice dependency is being resolved correctly. However, when trying to make the import com.google.inject.*
statement it seems that the library is not available:
I don't have this problem with any other imported dependencies, what am I doing wrong here?
回答1:
tl;dr Execute eclipse
task and refresh the project in Eclipse.
As a quick check of the import being really in the dependency, execute play console
and type in import com.google.inject.*
. If sbt console
can resolve the import, it's an issue with Eclipse that didn't seem to refresh the project.
Don't forget to reload
an active session of play
after every change to the build.
回答2:
Try this command on console in your project directory -
your project dir $:> play compile eclipse
and then refresh your project on eclipse.
Play doesn't have any plugin on eclipse but play provide the utility to import your project into eclipse. so whenever you add a new dependency you should compile and eclipsify your project otherwise eclipse will not understand the new dependency imports.
来源:https://stackoverflow.com/questions/26529648/why-is-eclipse-not-able-to-resolve-guice-import-in-play-2-2-x-application