public
Description: The Lift web framework for Scala
Home | Edit | New

About: Maven Mini Guide

Maven is the default tool used to create, build, test and manage lift based web application.

Create a new project (interactive)

Maven has an interactive mode, which you can call like so (providing mvn is on your $PATH)

mvn archetype:generate -DarchetypeCatalog=http://scala-tools.org/

Create a new project (non-interactive)

mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create \ 
 -DarchetypeGroupId=net.liftweb                             \
 -DarchetypeArtifactId=lift-archetype-blank                 \
 -DarchetypeVersion=1.0                                   \
 -DremoteRepositories=http://scala-tools.org/repo-releases  \
 -DgroupId=your.proj.gid -DartifactId=your-proj-id

Notes

  • Replace “lift-archetype-blank” with “lift-archetype-basic” to generate a project with basic users, authentication and a database.
  • You can replace “-DarchetypeVersion=1.0” with “-DarchetypeVersion=1.1-SNAPSHOT” to work against a lift 1.1 pre-release. (Use at your own risk.)

Default settings

If you would like scala-tools repo to be part of your default maven settings, put this in your settings.xml file, by default located in ~/.m2/settings.xml


<settings>
  <pluginGroups>
    <pluginGroup>net.sf.alchim</pluginGroup>
  </pluginGroups>
  <profiles>
    <profile>
      <id>default</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <pluginRepositories>
        <pluginRepository>
          <id>scala-tools.org</id>
          <name>Scala Tools Maven2 Repository</name>
          <url>http://scala-tools.org/repo-releases</url>
        </pluginRepository>
      </pluginRepositories>
      <repositories>
        <repository>
          <id>scala-tools.org</id>
          <name>Scala Tools Maven2 Repository</name>
          <url>http://scala-tools.org/repo-releases</url>
        </repository>
        <repository>
          <id>scala-tools.org.snapshots</id>
          <name>Scala Tools Maven2 Repository</name>
          <url>http://scala-tools.org/repo-snapshots</url>
          <snapshots />
        </repository>
      </repositories>
    </profile>
  </profiles>
</settings>

Building the war file

From the project directory (where the pom.xml file is located)

mvn package

Running the webapp

From the project directory (where the pom.xml file is located)

The following command runs a server with Jetty for development and test only.

mvn jetty:run -U

This command compiles and runs the tests before starting Jetty

Compiling the code in a loop (non-stop)

From the project directory (where the pom.xml file is located)

mvn scala:cc

Generate/update the eclipse configuration file

mvn eclipse:eclipse

Maven usage


usage: mvn [options] [<goal(s)>] [<phase(s)>]

Options:
 -q,--quiet                    Quiet output - only show errors
 -C,--strict-checksums         Fail the build if checksums don't match
 -c,--lax-checksums            Warn if checksums don't match
 -P,--activate-profiles        Comma-delimited list of profiles to
                               activate
 -ff,--fail-fast               Stop at first failure in reactorized builds
 -fae,--fail-at-end            Only fail the build afterwards; allow all
                               non-impacted builds to continue
 -B,--batch-mode               Run in non-interactive (batch) mode
 -fn,--fail-never              NEVER fail the build, regardless of project
                               result
 -up,--update-plugins          Synonym for cpu
 -N,--non-recursive            Do not recurse into sub-projects
 -npr,--no-plugin-registry     Don't use ~/.m2/plugin-registry.xml for
                               plugin versions
 -U,--update-snapshots         Forces a check for updated releases and
                               snapshots on remote repositories
 -cpu,--check-plugin-updates   Force upToDate check for any relevant
                               registered plugins
 -npu,--no-plugin-updates      Suppress upToDate check for any relevant
                               registered plugins
 -D,--define                   Define a system property
 -X,--debug                    Produce execution debug output
 -e,--errors                   Produce execution error messages
 -f,--file                     Force the use of an alternate POM file.
 -h,--help                     Display help information
 -o,--offline                  Work offline
 -r,--reactor                  Execute goals for project found in the
                               reactor
 -s,--settings                 Alternate path for the user settings file
 -v,--version                  Display version information

Main phases

  • validate – Validate that the project is correct and that all necessary information is available
  • compile – Compile the source code of the project
  • test – Test the compiled source code using a suitable unit testing framework. These tests should not require the code to be packaged or deployed
  • package – Take the compiled code and package it in its distributable format, such as a JAR.
  • integration-test – Process and deploy the package if necessary into an environment where integration tests can be run
  • verify – Run any checks to verify that the package is valid and meets quality criteria
  • install – Install the package into the local repository, for use as a dependency in other projects locally
  • deploy – Done in an integration or release environment, deploy copies the final package to the remote repository for sharing with other developers and projects.

more…

Glossary

archetype
A project template in Maven’s terminology

artifact
The main result of a project (e.g., a jar, a war, an ear, etc.)

goal
An available command on a maven plugin

groupId (of an artifact)
The unique identifier of the organization or group that created the project. The groupId is one of the key identifiers of a project and is typically based on the fully qualified domain name of your organization. For example org.apache.maven.plugins is the designated groupId for all Maven plug-ins.

artifactId (of an artifact)
The unique base name of the primary artifact being generated by this project. The primary artifact for a project is typically a JAR file. Secondary artifacts like source bundles also use the artifactId as part of their final name. A typical artifact produced by Maven would have the form -. (for example, myapp-1.0.jar ).

version (of an artifact)
The version of the artifact generated by the project. Maven goes a long way to help you with version management and you will often see the SNAPSHOT designator in a version, which indicates that a project is in a state of development.

WAR file (Web ARchive)
The archive of the webapp, following JEE convention

mvn
“mvn” is the name of the command line tool to call maven 2.×. To display help, run mvn help the project descriptor
The file ([project]/pom.xml) where all project information is stored (e.g., name, version, dependencies, license, mailing-list, etc.)

build lifecycle
The build lifecycle is defined by a sequence of phases. The main phases are:

  • compile – Compile the source code of the project
  • test – Test the compiled source code using a suitable unit testing framework. These tests should not require that the code be packaged or deployed
  • package – Take the compiled code and package it in its distributable format, such as a JAR or WAR.
  • integration-test – Process and deploy the package if necessary into an environment where integration tests can be run
  • install – Install the package into the local repository, for use as a dependency in other projects locally
  • deploy – Done in an integration or release environment, deploy copies the final package to the remote repository for sharing with other developers and projects.

A phase depends on the previous one, so when you request the phase test, then the phase compile is done first
(more information…)

repository (more…)
Maven uses repositories (local and remote) to store and to retrieve artifacts and their descriptors (pom). Artifacts include jar files, war files, etc., and they can be used as dependencies, maven plugins, and more. By default, maven searches for artifacts in the central repository. This is a “dedicated” repository for Scala stuff and is available at http://scala-tools.org/repo-releases/ (it hosts lift’s artifacts). If you wish to search for artifacts in the central repository, there is a search engine at http://mvnrepository.com .

Links: General Documentation

Links: Plugins

  • Plugins usefull for web projects
    • yuicompressor-maven-plugin : compress (Minify + Ofuscate) Javascript files and CSS files using YUI Compressor
    • winstone-maven-plugin : embed your warfile into/with the winstone JAR itself. This allows an all-in-one container plus web-application JAR file to run as a standalone application
    • others links

Doc about maven + scala/lift

  • maven for scala : an introduction to maven for scala user
  • About: Maven Archetypes? : info about the lift’s archetype
Last edited by eraserhd, Mon Nov 23 11:34:56 -0800 2009
Home | Edit | New
Versions: