Scaladin and SBT configuration

I thought maybe someone should start a thread for those who are using SBT to build Vaadin projects. There’s a few gotchas and places to get tripped up in an SBT Scaladin / Vaadin project. I’ll start off by giving my experience in adding DontPush OzoneLayer to an SBT project. Here’s what I wrote to the SBT mailing list, and I’m putting it here for future Vaadin users.

DontPush OzoneLayer) can be added to the sbt dependencies like so:

libraryDependencies ++= Seq(etc, “org.vaadin” % “dontpush-addon-ozonelayer” % “0.4.6”, etc.)

The problem is that for some reason Jetty gives the following exceptions:
org.eclipse.jetty.servlet.ServletHolder$1: java.lang.reflect.InvocationTargetException
… and so on, until:
Caused by: java.lang.UnsupportedOperationException: Please remove the atmosphere-compat-jetty from your classpath

Okay, so I add:
“org.vaadin” % “dontpush-addon-ozonelayer” % “0.4.6” exclude(“org.atmosphere”, “atmosphere-compat-jetty”)

But, that doesn’t exclude the atmosphere-compat-jetty from the lib_managed folder (I’ve set retrieveManaged := true) or the build (I still get the same error). Just to check to see if it was this dependency that was transitively bringing in the atmosphere-compat-jetty jar, I set:

“org.vaadin” % “dontpush-addon-ozonelayer” % “0.4.6” intransitive()

And that excluded it. And all the other jars it needs as well, of course. So, how to solve it? According to the old googlecode sbt pages I found a way to manually use the ivy xml to set the exclusion:

ivyXML :=


And that works. So, I guess the exclude() function isn’t working correctly? Or am I using it wrong? Although the sbt wiki is getting better, I wish it had a simple search box and more examples.

For future Vaadin / atmosphere users, you then have to add a second dependency after excluding that module:

“org.eclipse.jetty” % “jetty-websocket” % “8.0.1.v20110908”

After that it all works fine. Hope this helps folks in the future.

As a quick tip for anyone wanting to try out Scaladin with SBT there is a
Giter8
template for Scala + Vaadin projects. You can find it
here
. Just as an example, here are the required steps to get an SBT project running:

g8 ripla/vaadin-scala
<answer questions, enter for defaults>
cd <project dir>
sbt
container:start

Suggestions, bugfixes and comments are welcome. I’m also planning to do vaadin-scala-on-steroids kind of template to show some other frameworks alongside Scaladin e.g. Subcut, Scalatest…

Thanks Risto, the more information gathered into one thread the better.

Although, for me, I needed to compile a new GWT widgetset before container:start would work. Run the gwt-compile command from sbt to do this. You might also want to put

gwtVersion := "2.4.0"

after your seq(gwtSettings: _*) in the build.sbt file.


I just tested and it seemed to work fine for me.

Somehow I managed to miss the web.xml reference to the widgetset, thanks! It’s fixed now.

Thanks for the tip, I’ll look into that.

Christopher,
Would you mind posting the body of your build.sbt file? I was able to get DontPushOzone working with SBT on my machine recently, but only after a significant amount of hassle that involved many failed SBT configurations. Unfortunately the result doesn’t seem to work for the other contributors on my project.

Thanks and great job,

Steve Thompson

Hello Steve,

Sorry for the late reply – I have to remind myself to check for replies. Here is the build.sbt file you can use as a good start. Let me know if you need any other information!


build.sbt

here’s the code just case that gist goes away:

import net.thunderklaus.GwtPlugin._

name := "Scala Experiment Server"

scalaVersion := "2.9.1"

seq(gwtSettings: _*)

gwtVersion := "2.4.0"

seq(webSettings: _*)

// JRebel settings
seq(jrebelSettings: _*)

jrebel.webLinks <++= webappResources in Compile

//not sure which of these is necessary:
scanDirectories := Nil

scanDirectories in Compile := Nil

// uncomment this if we don't want to generate rebel.xml 
// jrebel.enabled := false

retrieveManaged := true

retrievePattern := "[type]
s/[organisation]
-[module]
-[artifact]
(-[revision]
)(-[classifier]
).[ext]
"

resolvers += "Vaadin add-ons repository" at "http://maven.vaadin.com/vaadin-addons"

ivyXML :=
  <dependency org="org.vaadin" name="dontpush-addon-ozonelayer" rev="0.4.6">
      <exclude org="org.atmosphere" module="atmosphere-compat-jetty"/>
  </dependency>

// basic dependencies
libraryDependencies ++= Seq(
  "com.vaadin" % "vaadin" % "6.7.6",
  "org.vaadin" % "dontpush-addon-ozonelayer" % "0.4.6",
  "org.vaadin.addons" % "scaladin" % "1.0.0",
  "org.eclipse.jetty" % "jetty-webapp" % "8.0.1.v20110908" % "container",
  "org.eclipse.jetty" % "jetty-websocket" % "8.0.1.v20110908"
)

// hack: sbt-gwt-plugin assumes that sources are in src/main/java
javaSource in Compile <<= (scalaSource in Compile)

gwtModules := List("org.cpoile.ExperimentServerWidgetset")

// more correct place would be to compile widgetset under the target dir and configure jetty to find it from there 
gwtTemporaryPath := file(".") / "src" / "main" / "webapp" / "VAADIN" / "widgetsets"

And the plugins.sbt file:


plugins.sbt

// xsbt-web-plugin
resolvers += "Web plugin repo" at "http://siasia.github.com/maven2"  

resolvers += "Jawsy.fi M2 releases" at "http://oss.jawsy.fi/maven2/releases"

libraryDependencies <+= sbtVersion(v => "com.github.siasia" %% "xsbt-web-plugin" % (v+"-0.2.11"))

// sbt idea
resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.0.0")

// JREBEL
resolvers += "Jawsy.fi M2 releases" at "http://oss.jawsy.fi/maven2/releases"

addSbtPlugin("fi.jawsy.sbtplugins" %% "sbt-jrebel-plugin" % "0.9.0")

// GWT compiler
resolvers += "GWT plugin repo" at "http://thunderklaus.github.com/maven"

addSbtPlugin("net.thunderklaus" % "sbt-gwt-plugin" % "1.1-SNAPSHOT")

Also forgot to add, you have to put ?restartApplication at the end of your url is order to see changes made to a running application.
e.g.:

localhost:8080/MyApp?restartApplication

Hi,

I’m new to Vaadin, but I feel adventurous and would like to try out the latest version, and with Scala. So I try to get a simple Vaadin “Hello World” to run with
Scala 2.10.1
Vaadin 7.0.3
Scaladin 3.0.0 (build from github sources)
sbt 0.12.2

I get some example code to compile, but when I run
sbt

container:start

all I see is

javax.servlet.UnavailableException: Servlet Not Initialized

and a stack trace.

Does someone by any chance have a working build.sbt for Scaladin 3 / Vaadin 7 ? Or maybe someone can point me to an example / hello world application for this combination somewhere?

Thanks,
Lutz

Here’s a simple sbt setup that works:

├── build.sbt
├── lib
│   └── scaladin_2.10-3.0.0-SNAPSHOT.jar
├── project
│   ├── plugins.sbt
└── src
    └── main
        ├── scala
        │   └── com
        │       └── example
        │           └── MyScaladinUI.scala
        └── webapp
            └── WEB-INF
                └── web.xml

build.sbt

name := "myproject"

scalaVersion := "2.10.1"

libraryDependencies ++= Seq(
  "com.vaadin" % "vaadin-server" % "7.0.3",
  "com.vaadin" % "vaadin-client-compiled" % "7.0.3",
  "com.vaadin" % "vaadin-themes" % "7.0.3",
  "javax.servlet" % "servlet-api" % "2.4",
  "org.eclipse.jetty" % "jetty-webapp" % "8.1.10.v20130312" % "container"
)

seq(webSettings :_*)

plugins.sbt

libraryDependencies += "com.github.siasia" %% "xsbt-web-plugin" % "0.12.0-0.2.11.1"

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="VaadinScala" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
        <display-name>Scaladin Application</display-name>
        <context-param>
                <description>
                Vaadin production mode</description>
                <param-name>productionMode</param-name>
                <param-value>false</param-value>
        </context-param>
        <servlet>
                <servlet-name>Scaladin Application</servlet-name>
                <servlet-class>vaadin.scala.ScaladinServlet</servlet-class>
                <init-param>
                        <param-name>ScaladinUI</param-name>
                        <param-value>com.example.MyScaladinUI</param-value>
                </init-param>
        </servlet>
        <servlet-mapping>
                <servlet-name>Scaladin Application</servlet-name>
                <url-pattern>/*</url-pattern>
        </servlet-mapping>
</web-app>

MyScaladinUI.scala

package com.example

import vaadin.scala._

class MyScaladinUI extends UI {
  content = Button("Click me!", Notification.show("Hello World!"))
}

Hi Henri,

sweet, thanks!

My web.xml was wrong, I tried to use the one generated by “g8 ripla/vaadin-scala” , but apparently servlet class and init parameter name have changed. But following your example it works fine.

Regards,

Lutz

Yes, that template is for Vaadin 6 and Scaladin 2.x.

-Henri

hello henri,

I tried to copy the example you gave, but I have an error while entering “sbt” :
scala.reflect.internal.FatalError: object Predef does not have a member $qmark$qmark$qmark
I add that I used this plugins.sbt:


libraryDependencies += “com.github.siasia” % “xsbt-web-plugin_2.9.2” % “0.12.0-0.2.11.1”


because sbt was unable to find the former file.
Do you know what’s wrong?

xsbt plugin was moved to https://github.com/earldouglas/xsbt-web-plugin, so you should add in plugin.sbt:

addSbtPlugin(“com.earldouglas” % “xsbt-web-plugin” % “0.7.0”)

Take a look into Henri’s example projects
here
and
here
, and visit plugin
website
.

By the way, it will be great achievement if you sort out plugins documentation in vaadin. Currently, for a significant amount of plugins they are located outside Vaadin site. Spring is an excellent example how documention should be presented.