I'm a software developer. I'm passionate, I like what I'm doing and I try to do it better every day. I like open technologies because that's where I'm coming from. Currently working as a freelancer on J2EE applications. Particularly interested in Scala, Liftweb and Functional Programming. Andrew has posted 14 posts at DZone. You can read more from them at their website. View Full User Profile

Liftweb setup in 10 minutes - IDE and project configuration

08.26.2011
| 8092 views |
  • submit to reddit

Scala is one of the coolest programming languages out there and Lift is a revolutionary web framework that really leverages many scala features.

But it can be daunting at the beginning, even just getting your workspace setup. In this article I will go through the basic setup of your IDE, it really takes a few minutes!

Even though I've always been an Eclipse person I'm using IDEA IntelliJ with Scala cause I think is way superior. Ok let's begin. You will need IntelliJ 10.5.1, Maven or SBT.

Create the project with maven

First step is to create the project and for that we will use lift maven archetype. For the persistence layer we will use the default lift mapper. Run this command

mvn archetype:generate   -DarchetypeGroupId=net.liftweb   
-DarchetypeArtifactId=lift-archetype-basic_2.8.1
-DarchetypeVersion=2.3
-DarchetypeRepository=http:/scala-tools.org/repo-snapshots
-DremoteRepositories=http://scala-tools.org/repo-snapshots
-DgroupId=com.playamatch -DartifactId=web

You can also create a JPA based project running the same command with

archetypeArtifactId=lift-archetype-jpa-basic_2.8.1

You already have a full liftweb project! You can even run it with maven itself using the command

mvn jetty-run

Download and configure IntelliJ

Next open IntelliJ and install the scala plugin. You need to go to File -> Setting. This is where you can access all the configuration options. The equivalent of Window -> Preferences in eclipse.

Now go to the plugins, pick scala right click "Download and Install" and once done restart the IDE.

You should be able to see your code with syntax highlights and navigate through the classes already. If you want you can also download the SBT plugin for IDEA. In this tutorial I will use the command line.

Another configuration change you might want to do if you are coming from eclipse if the shortcuts. IDEA comes with an eclipse profile that will allow you to keep using all the handy shortcuts you've learned so far.



Configure SBT

I would recommend using SBT for your projects with the scala compiler is very fast ( well as fast as it gets really ;) ) Here I am using SBT 0.10.1

You need to create a build.sbt in the project root folder. This is what mine looks like, it is pretty much the standard dependencies.

/build.sbt

name := "liftplay"

scalaVersion := "2.8.1"

seq(webSettings: _*)



// If using JRebel uncomment next line
//jettyScanDirs := Nil


resolvers += "Java.net Maven2 Repository" at "http://download.java.net/maven/2/"


libraryDependencies ++= {

val liftVersion = "2.3" // Put the current/latest lift version here

Seq(

"net.liftweb" %% "lift-webkit" % liftVersion % "compile->default",

"net.liftweb" %% "lift-mapper" % liftVersion % "compile->default",

"net.liftweb" %% "lift-wizard" % liftVersion % "compile->default")

}



// Customize any further dependencies as desired

libraryDependencies ++= Seq(

"org.eclipse.jetty" % "jetty-webapp" % "7.3.0.v20110203" % "jetty", // For Jetty 7

//"org.mortbay.jetty" % "jetty" % "6.1.22" % "jetty,test", // For Jetty 6, add scope test to make jetty avl. for tests

"org.scala-tools.testing" % "specs_2.9.0" % "1.6.8" % "test", // For specs.org tests

"junit" % "junit" % "4.8" % "test->default", // For JUnit 4 testing

"javax.servlet" % "servlet-api" % "2.5" % "provided->default",

"com.h2database" % "h2" % "1.2.138", // In-process database, useful for development systems

"ch.qos.logback" % "logback-classic" % "0.9.26" % "compile->default" // Logging

)


 

Then create another file under project/plugins (create these folders in your root project directory if you don't have them) called again build.sbt


/project/plugins/build.sbt
resolvers ++= Seq(

"Web plugin repo" at "http://siasia.github.com/maven2",

Resolver.url("Typesafe repository", new java.net.URL("http://typesafe.artifactoryonline.com/typesafe/ivy-releases/"))(Resolver.defaultIvyPatterns)

)



//Following means libraryDependencies += "com.github.siasia" %% "xsbt-web-plugin" % "0.1.0-""

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

last file is the build.properties under the project folder

/project/build.properties
project.organization=com.playamatch
project.name=liftplay
project.version=1.0-SNAPSHOT
sbt.version=0.10.1
def.scala.version=2.8.1
build.scala.versions=2.8.1
project.initialize=false

That's it. All you need to do now is an update to download all the dependencies

Get dependencies and run application

sbt update

and then you can run your new application

sbt ~jetty-run

Enable Debug for your application

If you want to debug your application just add the following to your sbt script

Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005

and then create a remote application debug configuration from Run -> Edit configurations. First check your defaults are like this then click on the plus sign


and name your run configuration!

Happy coding!!!

From http://www.devinprogress.info/2011/08/liftweb-setup-in-10-minutes-ide-and.html

Published at DZone with permission of its author, Andrew Salvadore.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Otengi Miloskov replied on Sat, 2011/08/27 - 6:41am

Awesome stuff and yes I agree with you, Scala and Lift Rocks!.

Neil Shannon replied on Sun, 2011/08/28 - 7:25am

You can also use the sbt-idea plugin (https://github.com/mpeltonen/sbt-idea) to generate your IntelliJ project files from an existing project. 

Just run:

sbt idea

from the command line to generate/re-generate your project after making any changes to your dependencies.

We use this to handle IDE setup for developers who want to work on any of our Lift projects checked in to github.

 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.