Scala + Eclipse + WebServer = A web app
Asked Answered
A

5

5

I want to develop a rather simple web application in Scala, with Lift or Play framework, using Eclipse as an environment and some simple webserver like Jetty. However, to my inexpressibly great surprise, I cannot setup the whole thing to work together. I also could not find any sensible simple and clear guide on how to do this. After a half day of searching, I came to an opinion that everyone around seem to use a mix of sbt/maven and feel it ok migrating from one to another and writing project config files manually just to get a simple blank project to begin with.

There is no plain simple way to create even an empty project. With Java I remember that it was a couple of clicks - to integrate a webserver into Eclipse, create a simple web app project and run it right from there. Where had gone the power and simplicity of Scala in this case? And that's only if I want to try Lift. What if I would like to try Play also, should I travel the same path again?

Is there anywhere a simple and complete guide that describes how to setup the environment so that it is possible to start developing the apps right away?

UPDATE: I have reached a successful Play project integration with Eclipse, with all the capabilities that Play has out-of-the-box, thanks to the advice of Peter Gwiazda. I am using this setup for developing right now. However, my question of interest remains: what are other ways to acheive similar functionality with other frameworks such as Lift, Scalatra and others?

Ankerite answered 26/3, 2012 at 10:21 Comment(2)
Where have you reached so far? Can you write simple Scala programs and build it all in one step? I am also learning Scala from scratch intending to learn Lift.Hammon
@aitchnyu Yes, I am already using Scala in production but not web-apps, just usual .jar applications with graphics, 3D and sound.. all this is no problem.. but the situation with web programming here just frightens me. It all looks like a soup made by a mad cook who put everything he can find around in his pot. That's not power.. that does not look like a part of the supernal Scala imposition for distributed and web development... I just hope that it is me stupid, not understanding something very simple, and not the real situation in the world as it is now.Ankerite
B
8

With Playframework 2.0 it's pretty simple. Just follow the tutorial http://www.playframework.org/documentation/2.0/ScalaTodoList

With Play you don't need anything else - Play already contains a server.

IMHO Play is way easier to work with than Lift.

Breakout answered 26/3, 2012 at 10:49 Comment(1)
Thanks, I have just gone exploring it! So far so good - seems plain and logical.Ankerite
J
6

EDIT
OK, you asked for it ;-)

Here's a bleeding edge setup for Scalatra with SBT Coffeescript & LESS (see HERE for SBT-Eclipse dependency management)

1) eclipsify a test project

2) in project root create "build.sbt" file:

import AssemblyKeys._
import Keys._

name := "your project name"

version := "1.0"

scalaVersion := "2.9.1"

fork in run := true 

resolvers ++= Seq(
  "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/",
  "Typesafe repository" at "http://typesafe.artifactoryonline.com/typesafe/ivy-releases/"
) 

seq(webSettings :_*)

seq(assemblySettings: _*)

seq(coffeeSettings: _*)

seq(lessSettings:_*)

(LessKeys.mini in (Compile, LessKeys.less)) := false

libraryDependencies ++= Seq(
  "org.scalatra"    %% "scalatra"   % "2.1.0-SNAPSHOT",
  "org.scalatra"    %% "scalatra-scalate"   % "2.1.0-SNAPSHOT",
  "org.scalatra"    %% "scalatra-lift-json"     % "2.1.0-SNAPSHOT",
  "org.scalatra"    %% "scalatra-anti-xml"  % "2.1.0-SNAPSHOT",
  "org.scalatra"    %% "scalatra-fileupload"    % "2.1.0-SNAPSHOT",
  "org.eclipse.jetty" % "jetty-webapp" % "8.1.0.RC2" % "test;container;provided",
  "javax.servlet"   % "javax.servlet-api" % "3.0.1" % "provided"
)

unmanagedBase <<= baseDirectory { base => base / "/src/main/webapp/WEB-INF/lib/" }

3) create folder "project" in root with plugins.sbt file:

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

resolvers += Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0-M3")

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.7.2")

addSbtPlugin("me.lessis" % "coffeescripted-sbt" % "0.2.2")

addSbtPlugin("me.lessis" % "less-sbt" % "0.1.9")

4) from terminal/command prompt start sbt & enable code reloading:

# sbt
> ~;container:start;container:reload /

Open up the Scalatra Book and start hacking ;-)

ORIGINAL
Have to mention it, but a micro framework a la Scalatra, Spray, or Unfiltered might be of interest as well.

That is, if you're not looking for the kitchen sink that Lift and Play provide; if you are looking for the kitchen sink and want to get rolling quickly, Play 2.0 does indeed look quite nice.

Jayme answered 26/3, 2012 at 14:18 Comment(3)
Yes, I have been looking at these frameworks and libraries, and I liked them by their descriptions, but I can't use them due to the problem described in the main question: I do not know how to create a Scala project that would work for a web app and tie it with a webserver. For now the only way that I could get closer to the goal is using the Play framework which includes everything out-of-the-box. I have successfully integrated it in an Eclipse project with eclipsify command.Ankerite
wow! that's explicit! and.. i knew it that time would come to learn sbt))) i want to try all the approaches since the area is new for me. so am going in this one now too.Ankerite
I added lift-json, anti-xml, and file-upload to the build.sbt file, as these are must-haves for most web devels (updated answer). Scalatra is pretty cool, somewhere between Play's kitchen sink and Spray's stateless approach. I'm finding it a nice transition from Grails, provides core essentials without handcuffing the inner hacker ;-)Jayme
P
4

Disclaimer: I'm a member of the Vaadin team.

You could also try out Vaadin which works perfectly with Scala, HOWTO here. You can also use Maven or SBT if you want. You should also check out Scaladin, the semi-official Scala wrapper for Vaadin.

Vaadin is a component based library (just one JAR with no dependencies) and it allows you to create your Ajax and HTML5 enabled UI in pure Scala without any HTML templates, RPC, XML or JavaScript.

Purvey answered 26/3, 2012 at 12:7 Comment(3)
Thanks! I have explored the Vaadin website and samples and it is very impressive! I suppose I will be using it in my web applications!Ankerite
I'm using Vaadin with Scala and can confirm it was very simple to setup with Eclipse. I'm not using Scaladin though, I've been using my own wrapper to make Vaadin more Scala friendly.Aleurone
hbatista: we would be very interested in your approach for wrapping Vaadin for Scala. Please give us your thoughts, eg. in this discussion: vaadin.com/forum/-/message_boards/view_message/530126Purvey
P
2

You could use my Maven prototype for Scalatra, then simply import the maven project into Eclipse. Quite nice and you're not forced to use SBT.

https://github.com/fancellu/scalatra-maven-prototype

Pocked answered 11/9, 2013 at 22:11 Comment(0)
T
1

You can have a look on my Github repo where I have a project that uses Lift and Jetty (as an embedded server). It's not well documented yet but is small enough to grasp how it's working

P4G Server Repo

The server starts from com.p4g.Server object (which is called within com.p4g.Main Application object )

My Lift boostrap object is located in boostrap.liftweb package

BTW, I'm also using ScalaQuery and ScalaZ

Turnkey answered 27/3, 2012 at 11:41 Comment(1)
weehee and Play is covered now too. all the three! this one is on my agenda too!Ankerite

© 2022 - 2024 — McMap. All rights reserved.