Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one change the location of the "webapp" directory for a Scalatra application?

By default, Scalatra expects the "webapp" directory to be at src/main/webapp. How could that be changed to, e.g., content/doc-root?

sbt allows for customizing its default directories using something like the following:

scalaSource <<= (baseDirectory)(_ / "src")

So I assume it's just a matter of knowing the right "configuration key" to use...

like image 555
Chris W. Avatar asked May 07 '13 02:05

Chris W.


2 Answers

@Kelsey Gilmore-Innis has the right answer, but since it's not accepted let's break it, break it, break it down.

First, I'm assuming you're following Getting started guide to install Scalatra using g8. Hopefully the same version I just got.

g8 scalatra/scalatra-sbt

What that g8 template did was to set up an sbt 0.13 build which uses scalatra-sbt 0.3.2 plugin:

addSbtPlugin("org.scalatra.sbt" % "scalatra-sbt" % "0.3.2")

This plugin internally uses JamesEarlDouglas/xsbt-web-plugin 0.4.0 to do the webapp-related settings.

xsbt-web-plugin 0.4.0

This is why xsbt-web-plugin becomes relevant even though you just want to change Scalatra's setting. The setting you need to rewire is called webappResources in Compile. How does that work?

rewiring webappResources

To rewire the setting, open project/build.scala. Add

import com.earldouglas.xsbtwebplugin.PluginKeys.webappResources

to the import clauses. Then change settings as follows:

  lazy val project = Project (
    "foo",
    file("."),
    settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ Seq(
      organization := Organization,
      name := Name,
      version := Version,
      scalaVersion := ScalaVersion,
      resolvers += Classpaths.typesafeReleases,
      webappResources in Compile := Seq(baseDirectory.value / "content" / "doc-root"),
      ...
    )
  )

Now move src/main/webapp to content/doc-root, reload sbt, and that should be it.

like image 147
Eugene Yokota Avatar answered Nov 11 '22 13:11

Eugene Yokota


The resource folder is a Jetty property. If you're running embedded Jetty, it's specified here. You can edit it manually or override by setting the PUBLIC environment variable.

You also can override it in your SBT build file. It uses the xsbt-web-plugin to run, and you can override that plugin's settings.

like image 4
Kelsey Gilmore-Innis Avatar answered Nov 11 '22 15:11

Kelsey Gilmore-Innis