users@glassfish.java.net

Re: Packaging JSP in JAR files

From: Jan Luehe <Jan.Luehe_at_Sun.COM>
Date: Mon, 15 Sep 2008 09:54:26 -0700

Jose,

On 09/15/08 09:10 AM, Jose Noheda wrote:
> Hi,
>
> Can I somehow precompile JSPs and pack them in a JAR file placed under
> WEB-INF in a way that glassfish understands it? What about a portable
> solution?

You can use the "jspc" utility, which has been available in GlassFish
v1/v2 and was recently ported to v3 (see
https://glassfish.dev.java.net/issues/show_bug.cgi?id=5883), to
precomile your JSPs. You then package the
generated servlet class files in a JAR file, which you store in your
webapp's WEB-INF lib.

If you do not anticipate any modifications to your JSP files once they
have been precompiled, you have the option
of not including the JSP files with your webapp.

There are 2 ways of doing this:

- Have the "jspc" utility create <jsp-file> mappings (one mapping per
JSP) in your web.xml, which will map a
  request for a JSP directly to the corresponding servlet. You can ask
"jspc" to either generate the complete
  web.xml file, or a web.xml snippet that contains all the <jsp-file>
mappings.

- If there are too many JSPs in your webapp, adding a <jsp-file> mapping
for each may not be practical,
  because of the size of the resulting web.xml. In this case, you can
still omit the JSP files from your webapp
  if you set the "usePrecompiled" init-parameter of the JspServlet to
true. This can be done either globally
  (in your domain's default-web.xml), or locally on a per-webapp basis
(in the webapp's sun-web.xml).

As a side note, please use "webtier_at_glassfish.dev.java.net" for any
GlassFish webtier related questions going
forward.

Thanks,

Jan