Using Maven
History Key
- New content
Removed content
Recent Versions
Choose two versions to compare, or click the link to view it.
Lift itself uses Maven as its default build system. (Even if you will develop with SBT instead of Maven, installing Maven can be an easy way to obtain the prerequisites.) If you don’t know whether you already have Maven installed, open a console and enter:
mvn --version
If Maven is installed, it will tell you the version and some other information. Currently Lift is built with Maven 2.2.1, but Maven 3 should be compatible for all we know so far.
On Linux, installing Maven with the Linux distribution’s package manager automatically installs the many libraries Maven needs, which you wouldn’t want to have to do manually. For example, on Ubuntu:
# apt-get install maven2 Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: ** snip ** Do you want to continue [Y/n]?
Mac OS X does not come with a Linux-style package manager, but there are several popular third-party package managers like brew and fink.
See also Sonatype’s guide to installing Maven.
Maven is like Brussels sprouts – either you love it or you hate it – but dependency management is essential for a large project like Lift with many modules and numerous dependencies to other libraries.
One particular valuable Maven feature are archetypes: Pre-defined project templates that can be “materialized” with a simple command. Lift offers several archetypes, e.g. a blank one, a basic one and one for using JPA, and this makes creating Lift projects super-fast. Select the appropriate archetype for your needs.
- lift-archetype-blank
- lift-archetype-basic
- lift-archetype-jpa-basic
Let’s create our first Lift project!
Open a console, cd into a suitable directory and enter the following command, replacing your.groupId and your.artifactId with suitable values. If you prefer to use a milestone release instead of the snapshot version you have to replace the archetypeVersion with the appropriate version, e.g. 2.3, and the remoteRepositories with http://scala-tools.org/repo-releases:
Using Scala 2.8.1 and Lift 2.3 final
Using a Unix shell call
mvn archetype:generate \ -DarchetypeGroupId=net.liftweb \ -DarchetypeArtifactId=lift-archetype-basic_2.8.1 \ -DarchetypeVersion=2.3 \ -DarchetypeRepository=http://scala-tools.org/repo-releases \ -DremoteRepositories=http://scala-tools.org/repo-releases \ -DgroupId=com.company \ -DartifactId=lift_test \ -Dversion=1.0
Using Scala 2.9.1 and Lift 2.4 milestone 4
Using a Unix shell call
mvn archetype:generate \ -DarchetypeGroupId=net.liftweb \ -DarchetypeArtifactId=lift-archetype-basic_2.9.1 \-DarchetypeVersion=2.4-M4-DarchetypeVersion=2.4 \ -DarchetypeRepository=http://scala-tools.org/repo-releases \ -DremoteRepositories=http://scala-tools.org/repo-releases \ -DgroupId=com.company \ -DartifactId=lift_test \ -Dversion=1.0
Using Scala 2.9.1 and Lift 2.4 snapshot
Using a Unix shell call
mvn archetype:generate \ -DarchetypeGroupId=net.liftweb \ -DarchetypeArtifactId=lift-archetype-basic_2.9.1 \ -DarchetypeVersion=2.4-SNAPSHOT \ -DarchetypeRepository=http://scala-tools.org/repo-snapshots \ -DremoteRepositories=http://scala-tools.org/repo-snapshots \ -DgroupId=com.company \ -DartifactId=lift_test \ -Dversion=1.0
(On Windows you have to replace the backslashs \ by carets ^ in order to form a many-line command.
Since 2009/04/24, archetypeRepository replace _remoteRepositories, you could set both to avoid troubles)
The last 3 arguments are about your newly created application: the package (com.company), name (lift_test) and version (1.0). Change it as needed.
For final vs snapshot release discussions see:
When SNAPSHOT is used Maven will create a local folder (lift_test) from the archetype repository
POM.XML
<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-mapper_${scala.version}</artifactId>
<version>2.4-SNAPSHOT</version>
</dependency>
Where ${scala.version} is 2.8.0, 2.8.1, 2.9.1 etc.
See the Lift discussion for details.
Directory structure
This will result in a new directory your.groupId with a typical Maven web application project layout. If you are not familiar with Maven’s convention over configuration approach please visit the Maven website for further information.
The screenshot below shows the most important directories and files. As you can see, the “blank” archetype already contains a properly configured web.xml and an index.html template binding to a HelloWorld.scala snippet.

Start the Webserver
In order to run our project enter:
mvn jetty:run
This will start the Jetty Servlet container properly configured with our project. Now you can access our new Lift-based web application at http://localhost:8080.
Congratulations! You just created your first Lift project. For further information, please visit our User Guide.
Enable automatic recompilation (optional)
Changes to scala code must be compiled before they are visible in the website. You can start the compiler in continuous mode by typing the following command into a second terminal. This will watch the filesystem and recompile any .scala file that has been changed since the last compile.
mvn scala:cc
After the compilation is complete, jetty should notice the updated classes and perform a restart. You should see the following message in the jetty terminal. This indicates that jetty has been restarted with the new version of the class.
[INFO] Restart completed at ...
Enable JRebel (optional)
JRebel (formerly known as JavaRebel) is a plugin for the Java Virtual Machine that enables on-the-fly reloading of changes made to Java class files.
ZeroTurnaround provide a free JRebel license for developers using Scala. You can obtain the license from their site.
Download and install JRebel.
In order to integrate JRebel into your build, first turn off automatic reloading in jetty by setting the scanIntervalSeconds value to 0:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.25</version>
<configuration>
<contextPath>/</contextPath>
<scanIntervalSeconds>0</scanIntervalSeconds>
</configuration>
</plugin>
Then add the following to your MAVEN_OPTS environment variable:
-noverify -javaagent:/path/to/jrebel/jrebel.jar
When you launch jetty, you should see the JRebel banner:
JRebel 3.1 (201006011508) (c) Copyright ZeroTurnaround OU, Estonia, Tartu.
When a Scala object is compiled (either manually or via mvn scala:cc) and that class is accessed (generally by reloading a webpage) JRebel will load and execute the new version of the class and you will see messages such as:
JRebel: Reloading class 'bootstrap.liftweb.Boot'.