java - 在 jetty 热部署简单的应用程序

标签 java jakarta-ee jetty

我目前正在使用 jetty hightide vesion 7 作为独立服务器。我有一个简单的 web 项目,其中包含几个 jsp 和支持类,我目前正在未爆炸的 war 中部署到 JETTY_HOME/webapps 目录。

目前,jetty 可以轻松获取任何静态 jsp/html 更改。如果我理解正确,我可以配置我的应用程序,以便 jetty 在不重新启动服务器的情况下接收任何类更改吗?我目前在我的 jetty-web.xml 中有:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<!--
    This is the jetty specific web application configuration file. When
    starting a Web Application, the WEB-INF/web-jetty.xml file is looked
    for and if found, treated as a
    org.eclipse.jetty.server.server.xml.XmlConfiguration file and is
    applied to the org.eclipse.jetty.servlet.WebApplicationContext objet
-->

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Call class="org.eclipse.jetty.util.log.Log" name="debug">
    <Arg>executing jetty-web.xml</Arg>
</Call>
<Set name="contextPath">/SimpleDynamicProject</Set>

</Configure>

我还创建了一个 SimpleDynamicProject.xml 并将其放在 JETTY_HOME/contexts 中。该文件包含:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<!--
    This is the jetty specific web application configuration file. When
    starting a Web Application, the WEB-INF/web-jetty.xml file is looked
    for and if found, treated as a
    org.eclipse.jetty.server.server.xml.XmlConfiguration file and is
    applied to the org.eclipse.jetty.servlet.WebApplicationContext objet
-->

<Configure class="org.eclipse.jetty.webapp.WebAppContext">

<Set name="contextPath">/SimpleDynamicProject</Set>
<Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/webapps/SimpleDynamicProject</Set>
</Configure>

我也不确定如何在我读到的 Debug模式下正确启动 Jetty。我尝试使用以下命令启动服务器:

java -Xdebug -jar start.jar OPTIONS=Server,jsp

java -Ddebug -jar start.jar OPTIONS=Server,jsp

这是我第一次使用 jetty,但到目前为止我真的很喜欢它。

感谢您的帮助。

最佳答案

你需要定义一个ContextDeployer具有非零扫描间隔:

<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">1</Set>
    </New>
  </Arg>
</Call>

关于调试,我想您的想法是使用 JPDA 连接远程调试器。为此,您需要设置 -agentlib:jdwp 选项1:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

将您的 IDE 调试器配置为连接到指定的端口。

1 如果目标 VM 是 5.0 或更新版本,-agentlib:jdwp 优于 -Xdebug-Xrunjdwp 选项仍然受支持。

关于java - 在 jetty 热部署简单的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2376596/

相关文章:

java - 为什么 switch (Java) 会发生这种情况?

java - Struts2-Full-Hibernate 插件是集成 Struts2 和 Hibernate 的标准方式吗?

java - Jetty 启动时间过长

java - 与 Jetty 的 TIME_WAIT 连接过多

java - 我为 AspectJ 使用哪个 maven 插件?

java - Java Mockito 模拟方法调用线程安全吗?

Java EE 共享库?

Java EE - 具有对同步方法的并发访问的单例 EJB

eclipse - Eclipse 中的 "Plugin not found for prefix"错误

java - 防止从Google App Engine发送重复的每日报告电子邮件