Why is Eclipse not able to resolve Guice import in

2019-09-18 08:33发布

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:

enter image description here

I don't have this problem with any other imported dependencies, what am I doing wrong here?

2条回答
迷人小祖宗
2楼-- · 2019-09-18 09:20

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.

查看更多
不美不萌又怎样
3楼-- · 2019-09-18 09:21

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.

查看更多
登录 后发表回答