目次

Version 5, last updated by Vlad Seryakov at Nov 02 04:28 UTC

Using Lift in Eclipse and terminal without MVN SBT

For those who does not want to use Maven or SBT for any reason, this is a tutorial that offers the development mode in “C++” way, keep all jars in one lib/ directory with symbolic links similar to native shared libraries.

Download

To start, download this script using wget, because this script will be needed in addition to java, bash and make.


# git clone git://github.com/vseryakov/lift-project.git

Now, assuming you are in the working directory start the script with the new app name


# lift-project/lift-project.sh demoapp

The script will produce some output, mostly urls and versions of the packages t downloads. It goes to Scala and Maven repositories and downloads latest versions of all packages required for Lift 2.1-
SNAPSHOT, including Lift as well. It uses metadata.xml for every package to figure out the latest version.

By default it stores all jars in $HOME/Scala/, for every jar file with version number a symbolic link is created which is a generic simple package name, for example jetty-6.1.25.jar has a symbolic link jetty.jar. This way all project files just refer to jetty.jar without knowing exact version and if jetty version will change, no need to update project files and classpaths.

Once the script is finished, your Lift demo applications is ready.

Now, there are 2 way to start it: in the terminal or in Eclipse. Let’s start Eclipse and make sure Scala IDE plugin is installed, if not, go to Help|Install New Software.. and add the repository for Scala IDE:
http://download.scala-ide.org/nightly-update-helios-2.8.0.final, then install Scala plugin. While plugin is being installed, return to the terminal and let’s see what we can do there.

Terminal mode

First, cd to our demoapp/ directory, it contains same structure as maven(mostly):


# cd demoapp
# make jetty

That’s right, using old fashioned make it will compile all scala files and fire up embedded jetty server on port 8080, same way as mvn jetty-run or sbt ~jetty:run.

This embedded server will also perform class monitoring for changes and restart the server in case of any modifications to the classes, it works similar to mvn jetty:run but without mvn. The source file for this jetty server in in the* src/test/scala/Jetty.scala* file, it is part of the project.
Now go to Demoapp and see demo in action.

This make stuff is just for fun, it is slow even the Scala compiler does incremental compilation, invoking java with all jars takes too much time but still it offers simple way to perform development in terminal.

Eclipse

Let’s return to Eclipse, assuming the Scala plugin is installed and Eclpse is restarted, let’s import exiting project by going to File|Import…. Navigate to the demoapp/ directory and finish import.

New Scala project will be created and compiled automatically. Scala 2.8 plugin works pretty well with Scala, very stable and all hints and hovers are working as well as well as completion and incremental build.

To start Jetty from Eclipse, in the Project Explorer navigate to src/test/scala/Jetty.scala and right click on it, then choose Run As…|Scala Appication.

To make sure jetty process does not exit with Out of memory error, go to Run|Run Configurations… and edit Scala Application|Jetty$ entry, in the Arguments||VM Arguments add the following:

-XX:MaxPermSize=512m -XX:+CMSClassUnloadingEnabled -Xmx512M -Xms64M

That’s it, the embedded Jetty server will run, in the Console there will be the same output as in terminal, it will restart automatically on any classes changes.

Summary

  • The script kind of mimics C++ development mode, keeps libraries in one directory with symbolic links to versioned jars
  • Uses same Maven repository for downloading
  • Produces project files for make and Eclipse
  • Includes Jetty server with automatic restart on changes.
  • Can be run without app name to just refresh jars
  • Can be run with -offline flag to just create new app without downloading new versions from the maven repository