How to load the modified classes which has been imported to scalate without jetty-restart?
I am using scalate as my view templates, and sbt + jrebel. But I found if the classes imported to scalate has been modified, we have to restart jetty, or there may be complication errors.
The code is pretty simple:
webapp/WEB-INF/web.xml
<web-app version="2.5">
<filter>
<filter-name>TemplateEngineFilter</filter-name>
<filter-class>org.fusesource.scalate.servlet.TemplateEngineFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>TemplateEngineFilter</filter-name>
<url-pattern>/*</url-pattern>
</filt开发者_StackOverflow社区er-mapping>
</web-app>
src/main/scala/test.scala
package test
object A {
def a() = "AAA"
}
webapp/index.jade
- import test.A._
= a()
Disable jetty's auto-reload
class TestProject(info: ProjectInfo) extends DefaultWebProject(info) {
override val scanDirectories = Nil
}
Then start jetty:
> sbt
> jetty-run
> ~prepare-webapp
Visit home page:
http://localhost:8080/
It displays correct:
AAA
Then I modify the test.scala
as:
package test
object A {
def a() = "AAA#######"
}
Visit page again, correct:
AAA#######
Then modify the method name:
package test
object A {
def b() = "AAA#######"
}
and index.jade
invoke b()
:
- import test.A._
= b()
Visit again, show error:
Server Error: We're sorry, but something went wrong.
We've been notified about this issue and we'll take a look at it shortly.
From this sample we don't know where is wrong, but in my another project, we can see the reason: Failed compiling index.jade, value b()
is not found
So I have to restart jetty:
> jetty-restart
Visit again, and everything goes well.
How to fix this issue, or is there any other way to work with scalate without restarting?
UPDATE
After nearly 1 week of trying, I have to give up. I tried all the solutions I can find, but it still can't be compiled without restart.
Now, I just run sbt without jrebel, and let jetty reload the webapp when classes are modified(not monitor scalate views). For now, it takes 3 to 5 seconds, which is not too long.
Finally, thanks for @James' help
See the answer on the user list
What mode are you running in? I believe the system property scalate.mode is defaulted to production in the source (https://github.com/scalate/scalate/blob/master/scalate-core/src/main/scala/org/fusesource/scalate/TemplateEngine.scala)
精彩评论