Getting Started

Lets get scalating!

Introduction

Lets try and get you up to speed using Scalate as quickly as possible.

This guide will assume you have a reasonably recent installation of Maven, say version 2.0.9 or later. If you don’t, please install one now.

Create a project

Lets create a new Jog project that we can use as a base on which to build.

If you have not done so already install the Scalate Tool. If you prefer you can create projects using the Scalate Maven archetypes via maven instead of using Scalate Tool

To see all of the available commands type this command into a command terminal

  scalate

Now to create a new project type

  scalate create guice myGroup myArtifact

You might want to change myGroup and myArtifact to whatever maven groupId and artifactId you want to use.

Now change directory to the newly created myArtifact directory (or whatever name you used for the artifactId)

  cd myArtifact  

You should now see a directory tree something like this

  src
  +--main
  |  |--resources
  |  +--scala
  |  |  |--myGroup
  |  +--webapp
  |     |--WEB-INF
  +--test
     +--scala
        |--myGroup

If this step didn’t work, let us know!

Hopefully you now have a base Jog project using Scalate, Scala, Jersey and Guice.

Run the new project

To run the project run the following Maven command

  mvn jetty:run

Now when the application starts up you should be able to point your browser at http://localhost:8080 to run the application.

Your application is now ready for you to create new JAXRS resource beans (in Scala or Java code) as well as rendering any Scalate templates in the src/main/webapp directory.

To start hacking on a template, try editing the src/main/webapp/index.scaml file which is used to render the home page (a Scaml template). Or try adding new templates.

For more detail on how the web application works please refer to the Jog documentation

Scalate console

While looking at the home page of your running application you should see a little icon near the top right of the screen which opens/closes the Scalate Console. Try opening it and try out its links.

The Scalate Console provides nice error messages if you make a typo in a template together with edit links to the source code, plus provides handy links to the current source, templates and layouts you are viewing in development mode along with a number of other features.

Please refer to the Console documentation for more detail.

Using SBT

You can also compile the code with SBT (or Simple build tool) if you prefer instead of Maven. Type the following commands into a terminal (the first command enters the SBT shell)

  sbt
  update
  compile

At the time of writing there are some issues with WAR overlays and SBT so jetty-run might not work correctly.

Diving deeper

Once you have the application working and you’ve played with the Console you might want to dive deeper into Scalate and understand how it works.