lift配置
install
maven
参考:https://www.assembla.com/wiki/show/liftweb/using_maven
mvn archetype:generate \ -DarchetypeGroupId=net.liftweb \ -DarchetypeArtifactId=lift-archetype-basic_2.10 \ -DarchetypeVersion=2.5 \ -DgroupId=com.company \ -DartifactId=lift_test \ -Dversion=1.0 \ -DarchetypeRepository=https://oss.sonatype.org/content/repositories/releases
start web app
mvn jetty:run
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.
http://www.zeroturnaround.com/scala-license/
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'.
debug
console
For maven:
$ mvn scala:console
For sbt:
$ sbt ... > console ... [info] Starting scala interpreter... [info] Welcome to Scala version 2.7.7.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_17). Type in expressions to have them evaluated. Type :help for more information. scala>
(If you get the error ?[error] Error running compile: Compilation failed? when executing the ?console? command, then first run the ?update? command. This is required when using lift-lift_22_sbt-2.2-0-g22a67aa.zip (current))
quit or Ctrl+D will exit the Scala console in both cases.
Using the Console
From your console you can import Lift modules and your own code. For example:
scala> import net.liftweb.common.{Box, Empty, Full} import net.liftweb.common.{Box, Empty, Full} scala> Full("something") res0: net.liftweb.common.Full[java.lang.String] = Full(something)
Probably your first console command, however, should be to execute the code that you’ve included in Boot.scala
to setup your app:
scala> new bootstrap.liftweb.Boot().boot
This is by no means necessary but is required if you’re using Mapper or Record and want to do a database operation during your console session.