/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. ---
  2. title: Using JRebel with Scalate
  3. in_menu: false
  4. --- name:overview
  5. # Dynamically reload code
  6. Reload Java or Scala code without restarting your web app
  7. --- name:content
  8. If 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.
  9. ## JRebel to the rescue!
  10. [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.
  11. Here's how you can use it in a web application with Scalate.
  12. * [Download JRebel](http://www.zeroturnaround.com/blog/free-javarebel-for-scala-users-zeroturnaround-announces/)
  13. * set your **MAVEN\_OPTS** environment variable to point to where you installed the jrebel jar. For example:
  14. export MAVEN_OPTS="-noverify -javaagent:$JREBEL_HOME/jrebel.jar"
  15. * run your web application in maven
  16. mvn jetty:run
  17. Now if your code is compiled by your IDE or a build process, the classes are automatically reloaded on the fly. Neat eh!
  18. For example if you run the following in another shell
  19. mvn scala:cc
  20. Then as you edit your scala code it will be recompiled using Scala's incremental compiler, then JRebel will auto-reload any recompiled classes.
  21. ## Using the Scalate JRebel plugin
  22. If 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.
  23. The 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.
  24. So for example if you are using maven then add this profile to your web application pom.xml
  25. {pygmentize:: xml}
  26. <profiles>
  27. <profile>
  28. <id>jrebel</id>
  29. <dependencies>
  30. <dependency>
  31. <groupId>org.fusesource.scalate</groupId>
  32. <artifactId>scalate-jrebel_${scala_compat_tag}</artifactId>
  33. <version>\${scalate-version}</version>
  34. </dependency>
  35. </dependencies>
  36. </profile>
  37. </profiles>
  38. {pygmentize}
  39. If you then run your web application as follows (assuming you've defined **MAVEN_OPTS**) as specified above)
  40. mvn jetty:run -Pjrebel
  41. ## Things to watch
  42. We'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.
  43. This 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
  44. mvn -Dscalate.workdir=/tmp/_scalate jetty:run