我使用 scalate 作为我的视图模板,以及 sbt + jrebel。但我发现如果导入到scalate的类被修改了,我们必须重新启动jetty,否则可能会出现复杂的错误。
代码非常简单:
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>
</filter-mapping>
</web-app>
src/main/scala/test.scala
package test
object A {
def a() = "AAA"
}
webapp/index.jade
- import test.A._
= a()
禁用jetty的自动重新加载
class TestProject(info: ProjectInfo) extends DefaultWebProject(info) {
override val scanDirectories = Nil
}
然后启动jetty:
> sbt
> jetty-run
> ~prepare-webapp
访问主页:
http://localhost:8080/
显示正确:
AAA
然后我修改test.scala
as:
package test
object A {
def a() = "AAA#######"
}
再次访问页面,正确:
AAA#######
然后修改方法名:
package test
object A {
def b() = "AAA#######"
}
和 index.jade
invoke b()
:
- import test.A._
= b()
再次访问,显示错误:
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.
从这个示例中我们不知道哪里出了问题,但是在我的另一个项目中,我们可以看到原因: Failed compiling index.jade, value b()
is not find
所以我有重启jetty:
> jetty-restart
再次访问,一切顺利。
如何解决这个问题,或者有没有其他方法可以在不重新启动的情况下使用 scalate?
更新
经过近1周的尝试,我不得不放弃。我尝试了所有能找到的解决方案,但不重新启动仍然无法编译。
现在,我只是在没有 jrebel 的情况下运行 sbt,并在修改类时让 jetty 重新加载 web 应用程序(不监视 scalate 视图)。目前来说,需要3到5秒,并不算太长。
最后,感谢@James的帮助
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>
</filter-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
发布评论
评论(2)
请参阅 答案 .com/group/scalate" rel="nofollow">用户列表
See the answer on the user list
你在什么模式下运行?我相信系统属性 scalate.mode 在源中默认为生产(https://github.com/scalate/scalate/blob/master/scalate-core/src/main/scala/org/fusesource/scalate/TemplateEngine)。斯卡拉)
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)