Using Maven

History Key

  • New content
  • Removed content

Recent Versions

Choose two versions to compare, or click the link to view it.

  1. 34. 4 months by fmpwizard
  2. 33. 4 months by cwhii
  3. 32. 7 months by leedm777
  4. 31. 7 months by josephboyle
  5. 30. 9 months by indrajitr
  6. 29. 9 months by indrajitr
  7. 28. about 1 year by indrajitr
  8. 27. over 1 year by indrajitr
  9. 26. over 1 year by indrajitr
  10. 25. over 1 year by Chaba
  11. 24. almost 2 years by Chaba
  12. 23. almost 2 years by dpp
  13. 22. almost 2 years by Chaba
  14. 21. almost 2 years by Chaba
  15. 20. almost 2 years by indrajitr
  16. 19. almost 2 years by Chaba
  17. 18. almost 2 years by knabe
  18. 17. almost 2 years by Chaba
  19. 16. almost 2 years by hcurrie
  20. 15. almost 2 years by hcurrie
  21. 14. almost 2 years by hcurrie
  22. 13. almost 2 years by hcurrie
  23. 12. almost 2 years by hcurrie
  24. 11. almost 2 years by Chaba
  25. 10. almost 2 years by Meddix
  26. 9. almost 2 years by lkuczera
  27. 8. almost 2 years by Chaba
  28. 7. about 2 years by david.bernard.31
  29. 6. about 2 years by hseeberger
  30. 5. about 2 years by hseeberger
  31. 4. about 2 years by hseeberger
  32. 3. about 2 years by hseeberger
  33. 2. about 2 years by hseeberger
  34. 1. about 2 years by hseeberger
 

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'.