PageRenderTime 29ms CodeModel.GetById 24ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/scalate-website/src/jrebel.page

http://github.com/scalate/scalate
Visualforce Page | 71 lines | 44 code | 27 blank | 0 comment | 0 complexity | a4a742ee97bccd6949e956ca31587aad MD5 | raw file
 1---
 2title: Using JRebel with Scalate
 3in_menu: false
 4--- name:overview
 5
 6# Dynamically reload code
 7Reload Java or Scala code without restarting your web app
 8
 9--- name:content
10If you are building a web application you want to be able to create and edit Java and Scala code on the fly without having to stop and restart your web container for each code change.
11
12## JRebel to the rescue!
13
14[JRebel](http://www.zeroturnaround.com/jrebel) allows you to hot reload bytecode on the fly in your application without having to restart your web container.
15
16Here's how you can use it in a web application with Scalate.
17
18* [Download JRebel](http://www.zeroturnaround.com/blog/free-javarebel-for-scala-users-zeroturnaround-announces/)
19* set your **MAVEN\_OPTS** environment variable to point to where you installed the jrebel jar. For example:
20
21    export MAVEN_OPTS="-noverify -javaagent:$JREBEL_HOME/jrebel.jar" 
22    
23* run your web application in maven
24
25    mvn jetty:run
26
27Now if your code is compiled by your IDE or a build process, the classes are automatically reloaded on the fly. Neat eh!
28
29For example if you run the following in another shell
30
31    mvn scala:cc
32    
33Then as you edit your scala code it will be recompiled using Scala's incremental compiler, then JRebel will auto-reload any recompiled classes.
34
35## Using the Scalate JRebel plugin
36
37If you have templates which depend on Scala code thats reloaded by JRebel, it might be that the templates by default are not auto-reloaded by JRebel. This is because by default JRebel is not aware of the source & classes directories used by Scalate to generate Scala code for each template and compile it.
38
39The easiest thing to do is to just depend on the scalate-jrebel plugin in your web application. This is a JRebel plugin which listens to classes being reloaded in JRebel and it flushes all the Scalate template classes to ensure that your template is recompiled against the latest code.
40
41So for example if you are using maven then add this profile to your web application pom.xml
42
43{pygmentize:: xml}
44<profiles>
45  <profile>
46    <id>jrebel</id>
47    <dependencies>
48      <dependency>
49        <groupId>org.fusesource.scalate</groupId>
50        <artifactId>scalate-jrebel_${scala_compat_tag}</artifactId>
51        <version>\${scalate-version}</version>
52      </dependency>
53    </dependencies>
54  </profile>
55</profiles>
56{pygmentize}
57
58If you then run your web application as follows (assuming you've defined **MAVEN_OPTS**) as specified above)
59   
60    mvn jetty:run -Pjrebel
61
62## Things to watch
63
64We've found that if you use **\_scalate** directory in the **WEB-INF** directory when running your web app using **jetty:run** JRebel really slows down the Scalate recompile step hugely; so its better to let Scalate use a work directory outside of the web application.
65
66This should happen by default now; if not specify the **scalate.workdir** system property to be the work directory you want scalate to use. For example
67
68    mvn -Dscalate.workdir=/tmp/_scalate jetty:run
69    
70  
71