Scalatra - 未找到:对象缩放
Scalatra - not found: object scalate
上下文: 我是第一次接触 Scalatra。我正在按照 Scalatra In Action as well as the sample code repo 提供的说明进行操作。我能够获得使用 g8 创建的模板项目。当我更新 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.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.
问题: 这里的错误消息对于第一次使用 Scalatra 的用户来说有点令人困惑。我在 PageController 存储库中使用了相同的代码,那么为什么我会看到这些错误以及如何解决这些错误?看起来我的 shell 没有将 scalate 库识别为现有库,但我的理解是 scalate 在安装时附带了带有 scalatra 的软件包,所以我很困惑。
您必须将以下依赖项添加到构建文件才能在 Scalatra 项目中使用 Scalate(Scala 中的模板引擎):
"org.scalatra" %% "scalatra-scalate" % ScalatraVersion
您可以在以下位置查看示例项目的构建配置:https://github.com/scalatra/scalatra-in-action/blob/master/chapter02/project/build.scala
顺便说一下,Scalatra in Action 是一本基于 Scalatra 2.4 的老书,而最新的主要版本是 Scalatra 2.8。尽管本书中的大部分主题对 Scalatra 2.8 仍然有效,但 Scalate 支持在 Scalatra 2.8 中已被弃用。我们建议在 Scalatra 2.8 中使用 Twirl 而不是 Scalate。
上下文: 我是第一次接触 Scalatra。我正在按照 Scalatra In Action as well as the sample code repo 提供的说明进行操作。我能够获得使用 g8 创建的模板项目。当我更新 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.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.
问题: 这里的错误消息对于第一次使用 Scalatra 的用户来说有点令人困惑。我在 PageController 存储库中使用了相同的代码,那么为什么我会看到这些错误以及如何解决这些错误?看起来我的 shell 没有将 scalate 库识别为现有库,但我的理解是 scalate 在安装时附带了带有 scalatra 的软件包,所以我很困惑。
您必须将以下依赖项添加到构建文件才能在 Scalatra 项目中使用 Scalate(Scala 中的模板引擎):
"org.scalatra" %% "scalatra-scalate" % ScalatraVersion
您可以在以下位置查看示例项目的构建配置:https://github.com/scalatra/scalatra-in-action/blob/master/chapter02/project/build.scala
顺便说一下,Scalatra in Action 是一本基于 Scalatra 2.4 的老书,而最新的主要版本是 Scalatra 2.8。尽管本书中的大部分主题对 Scalatra 2.8 仍然有效,但 Scalate 支持在 Scalatra 2.8 中已被弃用。我们建议在 Scalatra 2.8 中使用 Twirl 而不是 Scalate。