Context: I'm looking to pick up Scalatra for the first time. I'm following instructions from Scalatra In Action as well as the sample code repo provided. I'm able to get a template project created using g8. When I update the code in the PageController file and start the jetty server I get some really strange error messaging, see below.
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. I'm using the same code in the PageController repo so why am I seeing these errors and how can I resolve them? 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.
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:
"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
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. Though most of topics in the book are still effective for Scalatra 2.8, Scalate support has been deprecated in Scalatra 2.8. We recommend using Twirl instead of Scalate in Scalatra 2.8.