16Scala

VRaptor3 also supports controllers written in Scala. The required configurations and an example are featured in this chapter.

Dependencies and Configuration

The following jars must be added to your applications's WEB-INF/lib directory:

Now, VRaptor must be configured to load the relevant plugins. In the web.xml file, define the context-param section as below:

<context-param>
    <param-name>br.com.caelum.vraptor.packages</param-name>
    <param-value>br.com.caelum.vraptor.scala</param-value>
</context-param>

Then, add to the file the required changes to use Scalate as the view:

<servlet>
    <servlet-name>TemplateEngineServlet</servlet-name>
    <servlet-class>org.fusesource.scalate.servlet.TemplateEngineServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>TemplateEngineServlet</servlet-name>
    <url-pattern>*.ssp</url-pattern>
</servlet-mapping>

Example

A VRaptor3 controller written in Scala:

@Resource
class MyController {

    @Path(Array("/hello"))
    def myLogic = "Hello, world!"

}