jsp - how to precompile .jspf files with jasper2 in ant -


.jspf files "java server fragments" -- jsp intended inclusion () in other .jsp files.

precompiling .jsp files handy because exposes syntax errors, missing imports, java code errors, etc. @ build time rather run time. we've struggled typos in .jsp not showing until view page. i'm putting automatic task ant precompile jsp files. (see http://tomcat.apache.org/tomcat-7.0-doc/jasper-howto.html#web_application_compilation).

tomcat's jsp compiler jasper2 has built in assumption jsp files have '.jsp' file extension. goes against current recommendations use .jspf file extensions when appropriate.

the question: how code ant task invoke jasper2 (aka jspc) precompile .jsp files, including .jspf files?

-- answer

(see discussion below correction other answers related this)

use ant helper tasks build textual list of .jspf files compile , pass jasper2 task in jspfiles attribute. follows:

<target name="precompilejsp">      <taskdef name="jasper2" classname="org.apache.jasper.jspc">        <classpath refid="compile.classpath"/>     </taskdef>  <!-- guts of solution -->     <!-- jasper2 refuses precompile .jspf unless list them specifically. boo hoo. -->     <fileset id="jspffiles" dir="${appdir.build}">        <include name="**/*.jspf"/>       <include name="**/*.jsp"/>      </fileset>  <!-- turns set textual comma-separated list -->     <pathconvert targetos="unix" pathsep="," property="app.jspflist" refid="jspffiles"/>     <!-- echo message="jspf files are: ${app.jspflist}"/ -->  <!-- precompilation invoking jasper2 -->     <jasper2               validatexml="false"               uriroot="${appdir.build}"              jspfiles="${app.jspflist}"              webxmlfragment="${precompile_tmp_dir}/generated_web.xml"               outputdir="${precompile_tmp_dir}">     </jasper2>      <!-- compile .java sources generate 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 referenced what .jspf file extension? how compile it? (and elsewhere on web) .jspf files not compiled on own, , textually included via <jsp:include> references other files. claim , reasoning wrong. tomcat jasper .jsp compiler in fact compile .jspf stand-alone during normal display-time processing of .jsp , related .jspf files. can trivially seen inspecting /usr/share/tomcat/work/catalina/localhost/org/youdomain/yourpath/includefile_jspf.java. .java file generated stand-alone code .jspf file. bottom line <jsp:include> not work c's #include(), rather includes @ runtime output of jspf file in output of including-file, rather including source of jspf file source of .jsp file c have.

the claim in referenced answer web-inf/somejsp.jsp files cannot viewed end users false. common put .jsp files in web-inf , 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, specific, .jsp files in /web-inf cannot directly viewed end users, can forwarded-to servlet or other jsp file, , comprise entire web response -- <html> ... </html>. (.jspf, on other hand, contain snippet or fragment of html response --- <div>header-content</div>, example.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -