-- THE ANSWER
(see discussion below for correction to the other answers related to this)
Use ant helper tasks to build a textual list of .jspf files to compile and pass that to the jasper2 task in the jspfiles attribute. As follows:
<target name="precompilejsp">
<taskdef name="jasper2" classname="org.apache.jasper.JspC">
<classpath refid="compile.classpath"/>
</taskdef>
<!-- THIS is the guts of the solution -->
<!-- Jasper2 refuses to precompile .jspf unless we list them specifically. Boo hoo. -->
<fileset id="jspffiles" dir="${appdir.build}">
<include name="**/*.jspf"/>
<include name="**/*.jsp"/>
</fileset>
<!-- This turns the set into a textual comma-separated list -->
<pathconvert targetos="unix" pathsep="," property="app.jspflist" refid="jspffiles"/>
<!-- echo message="Jspf files are: ${app.jspflist}"/ -->
<!-- Do the precompilation by invoking Jasper2 -->
<jasper2
validateXml="false"
uriroot="${appdir.build}"
jspfiles="${app.jspflist}"
webXmlFragment="${precompile_tmp_dir}/generated_web.xml"
outputDir="${precompile_tmp_dir}">
</jasper2>
<!-- Now compile those .java sources to generate any error messages. -->
<mkdir dir="${precompile_tmp_dir}/WEB-INF/classes"/>
<javac srcdir="${precompile_tmp_dir}"
destdir="${precompile_tmp_dir}/WEB-INF/classes"
debug="${compile.debug}"
deprecation="${compile.deprecation}"
optimize="${compile.optimize}"
includeantruntime="false">
<classpath refid="compile.classpath"/>
</javac>
</target>
--- DISCUSSION
It has been stated in the referenced What is .jspf file extension? How to compile it? (and elsewhere on the web) that .jspf files are not generally to be compiled on their own, and that they are textually included via a <jsp:include>
references from other files. That claim and reasoning are wrong. The Tomcat Jasper .jsp compiler does in fact compile .jspf stand-alone during the normal display-time processing of .jsp and related .jspf files. This can be trivially seen by inspecting /usr/share/tomcat/work/Catalina/localhost/org/youdomain/yourpath/includefile_jspf.java. This .java file is generated as stand-alone code for your .jspf file. Bottom line is that <jsp:include>
does not work like C's #include(), rather it includes at runtime the output of the jspf file in the output of the including-file, rather than including the source of the jspf file into the source of the .jsp file as C would have.
The claim in that referenced answer that WEB-INF/somejsp.jsp files cannot be viewed by end users is also false. It is common to put ALL .jsp files in WEB-INF and to reference them in Servlet code gateways mapped in web.xml or other servlet request forwarding mechanisms:
RequestDispatcher dispatcher = servctxThis.getRequestDispatcher(
"/WEB-INF/JSP/thewholepage.jsp" );
dispatcher.forward(request, response);
So, to be specific, .jsp files in /WEB-INF cannot be directly viewed by end users, but they can be forwarded-to by any servlet OR other JSP file, and do often comprise an entire web response -- <HTML> ... </HTML>
. (.jspf, on the other hand, often contain a snippet or fragment of HTML response --- <DIV>header-content</DIV>
, for example.