简体   繁体   English

Scalatra - 未找到:object scalate

[英]Scalatra - not found: object scalate

Context: I'm looking to pick up Scalatra for the first time.上下文:我希望第一次使用 Scalatra。 I'm following instructions from Scalatra In Action as well as the sample code repo provided.我正在按照Scalatra In Action中的说明以及提供的示例代码库进行操作。 I'm able to get a template project created using g8.我能够获得使用 g8 创建的模板项目。 When I update the code in the PageController file and start the jetty server I get some really strange error messaging, see below.当我更新 PageController 文件中的代码并启动码头服务器时,我收到了一些非常奇怪的错误消息,请参见下文。

c:\Users\eric.barnes\Desktop\scalatra-cms>sbt
[info] welcome to sbt
1.4.5 (Oracle Corporation Java 16.0.2) 
[info] loading global plugins from C:\Users\eric.barnes\.sbt\1.0\plugins 
[info] loading settings for project scalatra-cms-build from plugins.sbt ... 
[info] loading project definition from C:\Users\eric.barnes\Desktop\scalatra-cms\project 
[info] loading settings for project hello from build.sbt ... 
[info] set current project to Scalatra CMS (in build 
  file:/C:/Users/eric.barnes/Desktop/scalatra-cms/) 
[info] sbt server started at local:sbt-server-dc962f233e7070ae620d 
[info] started sbt server sbt:Scalatra CMS> ~jetty:start [info] compiling 1 Scala source to 
  C:\Users\eric.barnes\Desktop\scalatra-cms\target\scala-2.13\classes ... 
[error] C:\Users\eric.barnes\Desktop\scalatra- 
  cms\src\main\scala\com\example\cms\PageController.scala:4:8: not found: object scalate 
[error] import scalate.ScalateSupport [error]        ^ 
[error] C:\Users\eric.barnes\Desktop\scalatra- 
  cms\src\main\scala\com\example\cms\PageController.scala:6:31: not found: type 
  ScalatraCmsStack [error] class PagesController extends ScalatraCmsStack { 
[error]                               ^ 
[error] C:\Users\eric.barnes\Desktop\scalatra- 
  cms\src\main\scala\com\example\cms\PageController.scala:8:3: not found: value get 
[error]   get("/pages/:slug") { 
[error]   ^ 
[error] C:\Users\eric.barnes\Desktop\scalatra- 
  cms\src\main\scala\com\example\cms\PageController.scala:9:5: not found: value contentType 
[error]     contentType="text/html" 
[error]     ^ 
[error] C:\Users\eric.barnes\Desktop\scalatra- 
  cms\src\main\scala\com\example\cms\PageController.scala:10:35: not found: value params 
[error]     PageDao.pages find (_.slug == params("slug")) match { 
[error]                                   ^ 
[error] C:\Users\eric.barnes\Desktop\scalatra- 
  cms\src\main\scala\com\example\cms\PageController.scala:11:26: not found: value ssp 
[error]       case Some(page) => ssp("/pages/show", "page" -> page) 
[error]                          ^ 
[error] 6 errors found [error] (Compile / compileIncremental) Compilation failed 
[error] Total time: 2 s, completed Oct 4, 2021, 10:51:45 AM [info] 1. Monitoring source files 
  for hello/jetty:start... [info]    Press <enter> to interrupt or '?' for more options.

Questions: The error messaging here is a little confusing for a first time Scalatra user.问题:这里的错误消息对于第一次使用 Scalatra 的用户来说有点令人困惑。 I'm using the same code in the PageController repo so why am I seeing these errors and how can I resolve them?我在 PageController 存储库中使用了相同的代码,那么为什么我会看到这些错误以及如何解决这些错误? It looks like my shell doesn't recognize the scalate library as an existing library but it's my understanding scalate comes packages with scalatra on install so I'm quite confused.看起来我的 shell 没有将 scalate 库识别为现有库,但我的理解是 scalate 在安装时附带了带有 scalatra 的软件包,所以我很困惑。

You have to add the following dependency to your build file to use Scalate (which is a template engine in Scala) in your Scalatra project:您必须将以下依赖项添加到构建文件中才能在 Scalatra 项目中使用 Scalate(Scala 中的模板引擎):

"org.scalatra" %% "scalatra-scalate" % ScalatraVersion

You can see the build configuration of the Sample project at: https://github.com/scalatra/scalatra-in-action/blob/master/chapter02/project/build.scala您可以在以下位置查看示例项目的构建配置: https://github.com/scalatra/scalatra-in-action/blob/master/chapter02/project/build.scala

By the way, Scalatra in Action is a little old book based on Scalatra 2.4 while the latest major version of Scalatra 2.8.顺便说一下,Scalatra in Action 是一本基于 Scalatra 2.4 的老书,而最新的主要版本是 Scalatra 2.8。 Though most of topics in the book are still effective for Scalatra 2.8, Scalate support has been deprecated in Scalatra 2.8.尽管本书中的大部分主题对 Scalatra 2.8 仍然有效,但 Scalate 支持在 Scalatra 2.8 中已被弃用。 We recommend using Twirl instead of Scalate in Scalatra 2.8.我们建议在 Scalatra 2.8 中使用Twirl而不是 Scalate。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM