【问题标题】:How to add WebJars to my Play app?如何将 WebJars 添加到我的 Play 应用程序?
【发布时间】:2014-12-19 23:58:50
【问题描述】:

为了在我的 Play 应用中使用 WebJars,我添加了以下路由

GET     /webjars/*file              controllers.WebJarAssets.at(file)

在我的 scala 模板中,我添加了以下几行:

<link rel='stylesheet' href='@routes.WebJarAssets.at(WebJarAssets.locate("css/bootstrap.min.css"))'>
<link rel='stylesheet' href='@routes.WebJarAssets.at(WebJarAssets.locate("css/bootstrap-theme.min.css"))'>

当我打开应用程序时,css 文件已完美加载。但是一运行activator eclipse,就会出现以下编译错误:

[info] Compiling 4 Scala sources and 2 Java sources to /Users/d135-1r43/play/blog/target/scala-2.11/classes...
[error] /Users/d135-1r43/play/blog/conf/routes:10: object WebJarAssets is not a member of package controllers
[error] GET     /webjars/*file              controllers.WebJarAssets.at(file)
[error] /Users/d135-1r43/play/blog/conf/routes:10: object WebJarAssets is not a member of package controllers
[error] GET     /webjars/*file              controllers.WebJarAssets.at(file)
[error] /Users/d135-1r43/play/blog/app/views/main.scala.html:8: not found: value WebJarAssets
[error]         <link rel='stylesheet' href='@routes.WebJarAssets.at(WebJarAssets.locate("css/bootstrap.min.css"))'>
[error]                                                              ^
[error] /Users/d135-1r43/play/blog/app/views/main.scala.html:9: not found: value WebJarAssets
[error]         <link rel='stylesheet' href='@routes.WebJarAssets.at(WebJarAssets.locate("css/bootstrap-theme.min.css"))'>
[error]                                                              ^
[error] four errors found
[error] (compile:compile) Compilation failed
[error] Could not create Eclipse project files:
[error] Error evaluating task 'dependencyClasspath': error

知道这里发生了什么吗?我需要在我的类路径中添加一些东西吗?

【问题讨论】:

  • 您的依赖项中有webjars-play吗?您需要将其添加到您的构建文件中:libraryDependencies += "org.webjars" %% "webjars-play" % "2.3.0-2"

标签: scala playframework-2.3 webjars


【解决方案1】:

我遇到了同样的错误,在我的 build.sbt 文件中添加以下行解决了这个问题。

libraryDependencies += "org.webjars" %% "webjars-play" % "2.4.0"

【讨论】:

    猜你喜欢
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 2014-10-27
    • 2014-09-30
    • 2011-07-21
    • 2019-09-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多