[英]Play framework: package javax.inject does not exist
In my Play 2.0 Framework Java project, the following line yields errors both in Eclipse and during the sbt compile step: 在我的Play 2.0 Framework Java项目中,以下行在Eclipse中和sbt编译步骤中均产生错误:
import javax.inject.*;
I already added the javax.inject
dependency to my build.sbt file: 我已经将
javax.inject
依赖项添加到我的build.sbt文件中:
libraryDependencies ++= Seq(
javaCore,
javaJdbc,
javaEbean,
javaWs,
javaFooBar,
cache,
"javax.inject" % "javax.inject" % "1",
"org.atmosphere" % "atmosphere-play" % "2.1.1"
)
and executed clean
, update
& eclipse with-source=true
like mad: 并像疯了一样执行
clean
, update
& eclipse with-source=true
[myproject] $ eclipse with-source=true
[info] About to create Eclipse project files for your project(s).
[info] Compiling 3 Scala sources and 12 Java sources to ./myproject/target/scala-2.11/classes...
[error] ./myproject/app/com/elements/legacy/LegacyController.java:3: object inject is not a member of package javax
[error] import javax.inject.*;
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
[info] Resolving jline#jline;2.11 ...
[error] Could not create Eclipse project files:
[error] Error evaluating task 'dependencyClasspath': error
I have the feeling that sbt does not throw errors in case a dependency could not be resolved (eg javaFooBar above). 我有一种感觉,如果无法解决依赖关系,sbt不会抛出错误(例如,上面的javaFooBar)。 How can this be activated?
如何激活它?
How can I properly build a Play 2.0 Java project using javax.inject? 如何使用javax.inject正确构建Play 2.0 Java项目?
Thanks a lot! 非常感谢!
Edit: 编辑:
Extending the repository list in project/plugins.sbt in the following way did the trick: 可以通过以下方式扩展project / plugins.sbt中的存储库列表:
// The repositories
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots"),
Resolver.sonatypeRepo("releases"),
Resolver.typesafeRepo("snapshots"),
Resolver.typesafeRepo("releases")
)
The dependencies
command as described by Donovan is very helpful to check whether a dependency could be resolved or not! Donovan描述的
dependencies
命令对于检查是否可以解决依赖项很有帮助!
This looks like a failure to reload the project definition within activator. 看起来好像无法在激活器中重新加载项目定义。
If I update my build.sbt with the following, the project will still compile correctly not because there are no problems with the dependency but because it doesn't know about the changes. 如果我使用以下命令更新build.sbt,则该项目仍将正确编译,这不是因为依赖项没有问题,而是因为它不知道更改。
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache,
javaWs,
"foo" % "bar" % "1.0"
)
Compile message: 编译消息:
[exampleApp] $ compile
[success] Total time: 0 s, completed 29-apr-2015 9:13:30
If I now reload
my project configuration, we'll start to see problems. 如果现在
reload
项目配置,我们将开始发现问题。
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: foo#bar;1.0: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: foo#bar;1.0: not found
This is exactly what you would see if you added a dependency that requires a special resolver, eg snapshots, etc. 如果添加了需要特殊解析器(例如快照等)的依赖项,这就是您所看到的。
Let's remove that line from build.sbt and reload
so we can compile correctly, and then add an import for a package that doesn't exist within the project. 让我们从build.sbt中删除该行并
reload
以便我们可以正确地进行编译,然后为项目中不存在的包添加导入。
build.sbt (followed by a reload) build.sbt(随后重新加载)
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache,
javaWs
)
Application.java Application.java
import play.*;
import play.mvc.*;
import views.html.*;
import foo.bar.*;
public class Application extends Controller {
public static Result index() {
return ok(index.render("Your new application is ready."));
}
}
Compiling this results in 编译结果为
[error] D:\tmp\exampleApp\app\controllers\Application.java:7: error: package foo.bar does not exist
[error] import foo.bar.*;
[error] ^
[error] 1 error
[error] (compile:compile) javac returned nonzero exit code
The two errors have very distinct signatures, and this combined with dependencies
as mentioned above should help guide you to the right place. 这两个错误具有截然不同的签名,并且如上所述,此签名与
dependencies
结合应有助于将您引导到正确的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.