Execute JSP with Jetty 7.3 without javac

2019-08-03 06:21发布

问题:

The problem: I have a web application which is served by Jetty webserver v 7.3. I have a JSP page in the application. When I run the Jetty on system which has JDK(has javac) installed everything works fine. I want to port this to a system which has JRE(does not have javac). When I run the Jetty I get an error.

The solution: Pre-compile the JSP into Servlet. Generate application war file which includes this servlet. Let jetty execute the Servlet in place of compiling and executing JSP at runtime.

I tried to pre-compile JSP using JSPC ant target. But it is generating an empty .java file. My target code is as follows.

<jspc srcdir="${web.dir}"
          destdir="${build.classes.dir}"
          package="x.y.z"
          verbose="9"
          classpathref="project.class.path">
      <include name="**/index.jsp"/>
    </jspc>

Kindly suggest me a proper approach. If my approach is correct, kindly point out the mistake that I am making in configuring the ant task.

回答1:

Don't use the ant supplied jspc task. It is deprecated, flaky, and only worked with Tomcat 4 installed (certain versions).

Instead, install Tomcat (whichever version best supports the same JSP/Servlet specs as your deployed Jetty) and call the Jasper compiler via the Tomcat provided Ant task. An example for Tomcat 5 is available here.

Note that once the JSP pages are compiled to Servlets, the Servlets are compiled to classes, etc. You don't need any of this "build environment" in your Jetty deployment environment.

Also note that the commentary near the end of the ant supplied jspc task. I don't know if it is still relevant, but it is interesting.



标签: java jsp Jetty