如何获得嵌入式Jetty Web服务器来转储其JSP的临时Java代码

时间:2008-09-18 10:27:41

标签: java jsp jetty

在OpenNMS中调试JSP页面时,我一直遇到这个问题。 Jetty wiki在webdefault.xml中讨论了keepGenerated(http://docs.codehaus.org/display/JETTY/KeepGenerated),但似乎不清楚这在嵌入式设置中是如何工作的。

3 个答案:

答案 0 :(得分:3)

我知道这已经很久了,但我还没有在互联网上的其他地方找到答案,而且似乎没有那么容易。希望这会对某人有所帮助:

从jetty-version.jar中提取你的webdefault.xml,我的是:C:\ Documents and org / mortbay / jetty / webapp / webdefault.xml文件中的Settings \ JB.m2 \ repository \ org \ mortbay \ jetty \ jetty \ 6.1.22 \ jetty-6.1.22.jar

将webdefault.xml放入我的项目目录

编辑webdefault.xml并添加以下行:

<servlet id="jsp">
 ....
  <init-param>
    <param-name>keepgenerated</param-name>
    <param-value>true</param-value>
  </init-param>

将以下内容添加到maven pom.xml配置中:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>maven-jetty-plugin</artifactId>
  <configuration>    
    <webDefaultXml>webdefault.xml</webDefaultXml>
  </configuration>
</plugin>

当你运行mvn jetty:run maven目标时,我的jsp代码现在保存在target \ work \ jsp \ org \ apache \ jsp \ WEB_002dINF \ jsp

答案 1 :(得分:2)

如果您使用的是Jetty 6,可以使用以下代码:

String webApp = "./web/myapp"; // Location of the jsp files
String contextPath = "/myapp";
WebAppContext webAppContext = new WebAppContext(webApp, contextPath); 
ServletHandler servletHandler = webAppContext.getServletHandler();
ServletHolder holder = new ServletHolder(JspServlet.class);
servletHandler.addServletWithMapping(holder, "*.jsp");
holder.setInitOrder(0);
holder.setInitParameter("compiler", "modern");
holder.setInitParameter("fork", "false");

File dir = new File("./web/compiled/" + webApp);
dir.mkdirs();
holder.setInitParameter("scratchdir", dir.getAbsolutePath());

答案 2 :(得分:0)

已经倾销了。 例如,如果您有一个名为index.jsp的文件,则会创建一个名为index_jsp.java的文件 只需在工作目录中搜索类似的东西。