我想让 Jetty 在生产服务器上运行,当我有一个新的代码包要部署时,我希望能够执行“sbt package”将我的代码打包到一个 war 文件中,然后将其复制到生产计算机的 webapp 文件夹。
这样合理吗?如果是这样,将 Jetty 作为守护进程启动的最佳方法是什么?它会看到新文件并自动重新加载我的应用程序还是我需要以某种方式重新启动它?
最佳答案
您所建议的主要问题是让服务器监听或监视 webapps 文件夹所需的配置将会影响生产。
虽然这种类型的配置非常适合开发,但不建议将其用于生产应用程序。
话虽如此,您正在寻找的是一个 ContextDeployer,它可以在 jetty.xml 中配置。有关确切的详细信息,请参阅您的特定 Jetty 版本的 Jetty 文档:
<!-- =========================================================== -->
<!-- Configure the context deployer -->
<!-- A context deployer will deploy contexts described in -->
<!-- configuration files discovered in a directory. -->
<!-- The configuration directory can be scanned for hot -->
<!-- deployments at the configured scanInterval. -->
<!-- -->
<!-- This deployer is configured to deploy contexts configured -->
<!-- in the $JETTY_HOME/contexts directory -->
<!-- -->
<!-- =========================================================== -->
<Call name="addLifeCycle">
<Arg>
<New class="org.mortbay.jetty.deployer.ContextDeployer">
<Set name="contexts"><Ref id="Contexts"/></Set>
<Set name="configurationDir"><SystemProperty name="jetty.home" default="."/>/contexts</Set>
<Set name="scanInterval">5</Set>
</New>
</Arg>
</Call>
“scanInterval”告诉服务器监视上下文文件夹。每 5 秒,它检查一次文件是否发生更改。
最后,要将 Jetty 作为守护进程启动,只需使用他们在/bin 文件夹中提供的脚本即可:
./jetty.sh start
要停止 Jetty,请运行:
./jetty.sh stop
要重新启动 Jetty,请运行:
./jetty.sh restart
再次参见The Jetty Documentation或The Webtide Website获取您正在运行的 Jetty 版本的确切文档。不同版本在服务器配置方式方面可能存在巨大差异。
关于java - 使用 SBT 的 Jetty 和 Scala 部署策略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10646558/