TOTD #100: Getting Started with Scala Lift on GlassFish v3

Yaaay, 100th tip! Read earlier tips here.
Scala is a strongly typed JVM language that provides benefits of functional programming and dynamic languages on the JVM. As a result you get flexibility of language such as Ruby and performance of Java. Lift is an MVC-based Web framework, based on Scala, that claims to pick the best of Rails (ease of development), Seaside (highly granular sessions and security), Django (access control), and Wicket (designer-friendly templating system).

Lift applications can run inside any Java application server. GlassFish v3 can run Rails and Django applications natively and can also run Wicket applications. This Tip Of The Day (TOTD) explains how to get started with Lift applications and run inside GlassFish v3.

  1. Create a new Lift project using Maven as shown:

    ~/samples/v3/lift >mvn archetype:generate -U -DarchetypeGroupId=net.liftweb 
    -DarchetypeArtifactId=lift-archetype-blank -DarchetypeVersion=1.0 
    -DremoteRepositories=http://scala-tools.org/repo-releases 
    -DgroupId=demo.helloworld -DartifactId=helloworld 
    -Dversion=1.0-SNAPSHOT
     [INFO] Scanning for projects...
     [INFO] Searching repository for plugin with prefix: 'archetype'.
     [INFO] org.apache.maven.plugins: checking for updates from central
    
     . . .
    
     [INFO] ------------------------------------------------------------------------
     [INFO] BUILD SUCCESSFUL
     [INFO] ------------------------------------------------------------------------
     [INFO] Total time: 14 seconds
     [INFO] Finished at: Tue Sep 01 16:11:34 PDT 2009
     [INFO] Final Memory: 12M/80M
     [INFO] ------------------------------------------------------------------------
    


    This creates a directory "helloworld" which looks like:

    ~/samples/v3/lift/helloworld >find .
    .
    ./pom.xml
    ./src
    ./src/main
    ./src/main/resources
    ./src/main/scala
    ./src/main/scala/bootstrap
    ./src/main/scala/bootstrap/liftweb
    ./src/main/scala/bootstrap/liftweb/Boot.scala
    ./src/main/scala/demo
    ./src/main/scala/demo/helloworld
    ./src/main/scala/demo/helloworld/comet
    ./src/main/scala/demo/helloworld/comet/.keep
    ./src/main/scala/demo/helloworld/model
    ./src/main/scala/demo/helloworld/model/.keep
    ./src/main/scala/demo/helloworld/snippet
    ./src/main/scala/demo/helloworld/snippet/.keep 
    ./src/main/scala/demo/helloworld/snippet/HelloWorld.scala
    ./src/main/scala/demo/helloworld/view
    ./src/main/scala/demo/helloworld/view/.keep
    ./src/main/webapp
    ./src/main/webapp/index.html
    ./src/main/webapp/templates-hidden
    ./src/main/webapp/templates-hidden/default.html
    ./src/main/webapp/WEB-INF
    ./src/main/webapp/WEB-INF/web.xml
    ./src/test
    ./src/test/resources
    ./src/test/scala
    ./src/test/scala/demo
    ./src/test/scala/demo/helloworld
    ./src/test/scala/demo/helloworld/AppTest.scala
    ./src/test/scala/LiftConsole.scala
    ./src/test/scala/RunWebApp.scala
    


    In this directory, "src/main/scala" contains Scala source code, "src/main/webapp" contains the HTML and other related artifacts, and "src/test/scala" contains a simple test case to test the generated application. The "demo/helloworld/model" directory is used for models, "demo/helloworld/snippet" for controller, and "demo/helloworld/view" for views. The Lift Getting Started Guide provides a detailed explanation of how the different components work together to provide the end result.
  2. Create a WAR file of the application as:
    ~/samples/v3/lift/helloworld >mvn package [INFO] Scanning for projects...
     [INFO] ------------------------------------------------------------------------
     [INFO] Building helloworld
     [INFO] task-segment: [package]
     [INFO] ------------------------------------------------------------------------
     [INFO] artifact org.scala-tools:maven-scala-plugin: checking for updates from scala-tools.org
     [INFO] artifact org.scala-tools:maven-scala-plugin: checking for updates from central 
    
     . . . 
    
     [INFO] Building war: /Users/arungupta/samples/v3/lift/helloworld/target/helloworld-1.0-SNAPSHOT.war
     [INFO] ------------------------------------------------------------------------
     [INFO] BUILD SUCCESSFUL
     [INFO] ------------------------------------------------------------------------
     [INFO] Total time: 9 minutes 25 seconds
     [INFO] Finished at: Tue Sep 01 16:42:32 PDT 2009
     [INFO] Final Memory: 24M/80M
     [INFO] ------------------------------------------------------------------------
    


    This generates "target/helloworld-1.0-SNAPSHOT.war" file.
  3. The WAR file can be easily deployed to GlassFish v3. Download the latest GlassFish v3 promoted build (61 as of this writing) and unzip. Start the GlassFish server as:
    ~/tools/glassfish/v3/61/glassfishv3 >./bin/asadmin start-domain --verbose
    
    Sep 2, 2009 3:43:09 PM com.sun.enterprise.admin.launcher.GFLauncherLogger info
    INFO: JVM invocation command line:
    
    . . .
    
    Sep 2, 2009 3:46:01 PM OSGiModuleImpl start
    INFO: Started bundle org.glassfish.security [174]
    Sep 2, 2009 3:46:02 PM OSGiModuleImpl start
    INFO: Started bundle org.glassfish.deployment.javaee-full [51]
    

    and deploy the WAR file as:
    ~/samples/v3/lift/helloworld >~/tools/glassfish/v3/8-31/glassfishv3/bin/asadmin deploy target/helloworld-1.0-SNAPSHOT.war
    
    Command deploy executed successfully.
    


    The app is now accessible at "http://localhost:8080/helloworld-1.0-SNAPSHOT/" and the output looks like:

What application server are you using to deploy your Lift applications ?

Please leave suggestions on other TOTD that you’d like to see. A complete archive of all the tips is available here.

Technorati: totd scala lift glassfish v3

Comments:

"Lift Getting Started Guide" has moved here:
http://liftweb.net/getting_started
The Lift Wiki has a "Getting Started" guide with more build options:
http://www.assembla.com/wiki/show/liftweb/Getting_Started

Posted by Victor on December 01, 2010 at 07:38 PM PST #

"Lift Getting Started Guide" has moved here:
/getting_started

The Lift Wiki has a "Getting Started" guide with more build options.

Posted by Victor on December 01, 2010 at 07:51 PM PST #

PS
I tried to post in my previous comment the new "Lift Getting Started Guide" and the Wiki URLs, but had a very hard time, because TypePad AntiSpam rejects any comment containing something looking like a URL. I understand you want to block spam, but there must be other much better ways to do that (like e.g. Captchas).

Posted by Victor on December 01, 2010 at 07:58 PM PST #

Post a Comment:
Comments are closed for this entry.
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today