Categorist's Notes

Scala 2.8.0 + Lift 2.1 + IntelliJ: First Step(s)

by Vlad Patryshev

November 9, 2010



Summary

Transition to Scala 2.8 and Lift 2.1 turned the usual beginner trails impenetrable. It took me more than a week to figure out how to start with Lift on IntelliJ if you use Scala 2.8. Here's my experience.


First, I have to thank Sim for scala/lift/sbt cheatsheet for the Scala 2.7.7 version. So, what is the problem? Scala 2.8.0 is too new, and if you just started learning Scala Lift, and you do not want to go back to 2.7.7, you discover yourself in murky waters of undocumented failures, just because you have to figure out where exactly you should find the new code, how to run sbt, what to do with maven, and, most importantly, how can you start developing anything - probably in IntelliJ, which has the most mature Scala plugin at the time of this writing. I did carefully read (many times) the "sbt cheatsheet" referenced above, and, well, it is good, but the problem is, it is no good with Scala 2.8.0. So this is my story.

The Goal

You do not know where to start;

When you follow the hints, some important steps are missing;

Or you succeed, but you wind up with older versions of Scala, Lift, prototype code.

Prerequisites

sbt

java -Xmx512M -jar \home\yourname\scala\sbt-launch-0.7.4.jar

Getting the Sample, Making It Run

mkdir oursample cd oursample git clone git://github.com/lift/lift_21_sbt.git

mvn archetype:generate -U -DarchetypeGroupId=net.liftweb -DarchetypeArtifactId=lift-archetype-basic -DarchetypeVersion=2.0-scala280-SNAPSHOT -DarchetypeRepository=http://scala-tools.org/repo-snapshots -DremoteRepositories=http://scala-tools.org/repo-snapshots -DgroupId=myFirstLiftApp -DartifactId=lift_21_sbt

lift_21_sbt

pom.xml

sbt

cd lift_21_sbt ../../sbt

update

jetty-run

You are familiar with Scala; you use IntelliJ for development; you are aware of the magic of sbt ; now you want to try Lift for your experimental web app. You just bought a Scala Lift book, or you go to Lift Getting Started page, or to another Lift Getting Started page, and you encounter two problems:We have to fix this.You probably already have the following installed:You will need the following:Create a script for running, something likeFirst, create a directory where we will have our sample code, and check the code out from lift repository:Since we want to work in IntelliJ, let's run maven to generate an "archetype" from which we'll build IntelliJ project:See thatcontains the maven file. You can already run the sample application viaAt prompt, enterand then enterIn a minute or two you will have jetty run the sample app; just check out http://localhost:8080

But this is not our goal; we want a project for IntelliJ.

Preparing IntelliJ Project

Plugins

sbt

maven

File

Settings

Plugins

sbt

Settings

SBT

sbt.jar

New Project

File

New Project...

Import project from external model

root

.../lift_21_sbt

pom.xml

myFirstLiftApp:lift_21_sbt:1.0-SNAPSHOT

Next

Finish

Run

Edit Configurations

Edit Defaults

Before launch

Make

Run SBT Action / jetty-run

Creating Deployment War

sbt, right? type package - and very soon you can find in .../lift_21_sbt/target/scala_2.8.0 a war file (with a weird name). You can deploy this file in Tomcat or Jetty, on your server - it runs the sample Lift app when launched. Talk Back! Have an opinion? Readers have already posted 6 comments about this weblog entry. Why not add yours? RSS Feed If you'd like to be notified whenever Vlad Patryshev adds a new entry to his weblog, subscribe to his RSS feed. About the Blogger Vlad Patryshev was born in Russia, graduated from Leningrad University, majoring in Algebra; His studies combined practical programming with interests in category and topos theory. He spent 7 years at Borland, 3.5 years at Google, and is now at Telenav, investigating the brave new mobile world. This weblog entry is Copyright © 2010 Vlad Patryshev. All rights reserved.

You already have Scala plugin. You will needandplugins installed andis where you find this. After installingplugin, go toand set the right location ofAs a, select the directorywhere you have the newly-generatedfile. IntelliJ will discover; click throughand. In a minute or two you will see a project created; you could compile it... You are all set. Tweak the code ad libitum, compile... You may want to fix run configuration for scala console:->->; go to theoptions, uncheckand choose. Then, when you have your code open, run it; sbt will launch jetty while you have scala console; here I am at loss on why do we need this console. But jetty works!You are still running