The Artima Developer Community
Sponsored Link

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

6 replies on 1 page. Most recent reply: Mar 21, 2011 2:52 AM by jeff crilly

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
Vlad Patryshev

Posts: 4
Nickname: patryshev
Registered: Apr, 2008

Scala 2.8.0 + Lift 2.1 + IntelliJ: First Step(s) (View in Weblogs)
Posted: Nov 8, 2010 10:52 PM
Reply to this message Reply
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.
Advertisement
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 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:
  • 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.
We have to fix this.

Prerequisites

You probably already have the following installed: You will need the following: Create a script for running sbt, something like
java -Xmx512M -jar \home\yourname\scala\sbt-launch-0.7.4.jar 

Getting the Sample, Making It Run

First, create a directory where we will have our sample code, and check the code out from lift repository:
mkdir oursample
cd oursample
git clone git://github.com/lift/lift_21_sbt.git
Since we want to work in IntelliJ, let's run maven to generate an "archetype" from which we'll build IntelliJ project:
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
See that lift_21_sbt contains the maven file pom.xml. You can already run the sample application via sbt:
cd lift_21_sbt
../../sbt
At prompt, enter
update
and then enter
jetty-run
In 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

You already have Scala plugin. You will need sbt and maven plugins installed and enabled. FileSettingsPlugins is where you find this. After installing sbt plugin, go to SettingsSBT and set the right location of sbt.jar

New Project

FileNew Project...Import project from external model As a root, select the directory .../lift_21_sbt where you have the newly-generated pom.xml file. IntelliJ will discover myFirstLiftApp:lift_21_sbt:1.0-SNAPSHOT; click through Next and Finish. 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: Run -> Edit Configurations -> Edit Defaults; go to the Before launch options, uncheck Make and choose Run SBT Action / jetty-run. 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!

Creating Deployment War

You are still running 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.


Penelope Rabon

Posts: 1
Nickname: 65738
Registered: Apr, 2009

Re: Scala 2.8.0 + Lift 2.1 + IntelliJ: First Step(s) Posted: Nov 11, 2010 8:58 AM
Reply to this message Reply
I'm confused on editing the Idea run configuration. When I click on "Run|Edit Configurations|Edit Default, I get a dialog box as expected, but there is a long list of defaults to choose from -- AIR, Applet, Flex, Maven, Rails, etc. I do see 4 scala related ones ... Scala compilation server, scala console, Scala script, Scala test. Is it one of these I'm supposed to do the "Before launch ... " on? I'm currently using the "scala console" setting. It works, but after my program compiles, the Idea window leaves me at the scala console prompt "scala>" -- which is to be expected I guess since that is the configuration I'm doing "Before launch" on.
Is this the recommended default setup?

Thanks in advance,
P.R.

Vlad Patryshev

Posts: 4
Nickname: patryshev
Registered: Apr, 2008

Re: Scala 2.8.0 + Lift 2.1 + IntelliJ: First Step(s) Posted: Nov 11, 2010 2:02 PM
Reply to this message Reply
> I'm confused on editing the Idea run configuration. When
> I click on "Run|Edit Configurations|Edit Default, I get a
> dialog box as expected, but there is a long list of
> defaults to choose from -- AIR, Applet, Flex, Maven,
> Rails, etc. I do see 4 scala related ones ... Scala
> compilation server, scala console, Scala script, Scala
> test. Is it one of these I'm supposed to do the "Before
> launch ... " on?

Right, I never tried it. I'll remove it from the text, then will try to figure out what's the right thing to do. Thanks!

Bjarte S. Karlsen

Posts: 2
Nickname: meus78
Registered: Dec, 2007

Re: Scala 2.8.0 + Lift 2.1 + IntelliJ: First Step(s) Posted: Nov 16, 2010 2:17 AM
Reply to this message Reply
Have you tried the sbt-idea[1] to generate the idea project files from the sbt model? It can be used as a processor so you do not have to alter the sbt project files in any way.

Then you can skip the maven archetype step and you can just open the intellij project file instead of importing an external model.

[1] https://github.com/mpeltonen/sbt-idea

Vlad Patryshev

Posts: 4
Nickname: patryshev
Registered: Apr, 2008

Re: Scala 2.8.0 + Lift 2.1 + IntelliJ: First Step(s) Posted: Nov 16, 2010 2:22 AM
Reply to this message Reply
sbt-idea: never heard of this; thanks a lot for the hint. Sure I did not like the thought of having to use maven.

Will try.

Liutauras Diu

Posts: 3
Nickname: lidi
Registered: Dec, 2010

Re: Scala 2.8.0 + Lift 2.1 + IntelliJ: First Step(s) Posted: Dec 2, 2010 7:55 PM
Reply to this message Reply
I've tried to set "Before launch.." scala console. But it didn't work for. I would just flood my console with bunch of Downloading ... message and localhost:8080 wouldn't work.
I did it on Scala compilation server and it seems working.
But still not sure what Vlad had in mind.

L

jeff crilly

Posts: 1
Nickname: jeffcrilly
Registered: Mar, 2011

Re: Scala 2.8.0 + Lift 2.1 + IntelliJ: First Step(s) Posted: Mar 21, 2011 2:52 AM
Reply to this message Reply
Some of this is a bit dated, and obviously the files will evolve over time.

Just a heads up folks.. if the mvn archetype:generate fails you might want to double check the archetype version. E.g. this command worked for me...

mvn archetype:generate -U \
-DarchetypeGroupId=net.liftweb \
-DarchetypeArtifactId=lift-archetype-basic_2.8.1 \
-DarchetypeVersion=2.3-SNAPSHOT \
-DarchetypeRepository=http://scala-tools.org/repo-snapshots \
-DremoteRepositories=http://scala-tools.org/repo-snapshots \
-DgroupId=$1 -DartifactId=$2

(btw, I put that in a "genlift" script for ease of use.)

Flat View: This topic has 6 replies on 1 page
Topic: Open source saves another marriage Previous Topic   Next Topic Topic: Hybridizing Java


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us