How to combine jsp precompiled web.xml fragment with main web.xml using Ant

We have a regular web.xml for our web application that contains some jsp and jsp tag files. I want to switch to using precompiled jsp. I have a pre-compilation going on in the ok assembly, and it generates a web.xml fragment, and now I want to combine the fragment into the main web.xml.

Is there a directive like include for web.xml that will allow me to include a snippet.

Ideally, I leave things as for DEV, since it is useful to change jsp "on the fly" and immediately see the changes, but then for UAT / PROD, jsp will be precompiled and therefore will work faster.

+5
source share
5 answers

I am using Tomcat jasper ANT tasks in my project, which precompiles JSP into servlets and adds new servlet mappings to the original web.xml. In DEV builds, just skip this step and deploy the JSP without first compiling and modifying web.xml.

    <?xml version="1.0"?>
<project name="jspc" basedir="." default="all">
 <import file="${build.appserver.home}/bin/catalina-tasks.xml"/>

 <target name="all" depends="jspc,compile"></target>

 <target name="jspc">
  <jasper
   validateXml="false"
   uriroot="${build.war.dir}"
   webXmlFragment="${build.war.dir}/WEB-INF/generated_web.xml"
   addWebXmlMappings="true"
   outputDir="${build.src.dir}" />
 </target>

 <target name="compile">
  <javac destdir="${build.dir}/classes"
   srcdir="${build.src.dir}"
   optimize="on"
   debug="off"
   failonerror="true"
   source="1.5"
   target="1.5"
   excludes="**/*.smap">
   <classpath>
    <fileset dir="${build.war.dir}/WEB-INF/classes">
     <include name="*.class" />
    </fileset>
    <fileset dir="${build.war.lib.dir}">
     <include name="*.jar" />
    </fileset>
    <fileset dir="${build.appserver.home}/lib">
     <include name="*.jar" />
    </fileset>    
    <fileset dir="${build.appserver.home}/bin">
     <include name="*.jar"/>
    </fileset>
   </classpath>
    <include name="**" />
    <exclude name="tags/**"/>
  </javac>
 </target>

 <target name="clean">
  <delete>
   <fileset dir="${build.src.dir}"/>
   <fileset dir="${build.dir}/classes/org/apache/jsp"/>
  </delete>
 </target>
</project>

JSP web.xml, XSLT, ( ) - xml .

+4

Doh - jasper2 web.xml - addWebXmlMappings

    <jasper2
         validateXml="false"
         uriroot="${web.dir}"
         addWebXmlMappings="true"
         webXmlFragment="${web.dir}/WEB-INF/classes/jasper_generated_web.xml"
         outputDir="${web.dir}/WEB-INF/jsp-src" />

, ...

, , .

+4

XML ( ), XSLT. , . , , .

web.xml XML- <!-- @JSPS_MAP@ --> <servlet> <servlet-mapping>,

  <servlet>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>my.servlets.MyServlet</servlet-class>
  <servlet>

  <!-- @JSPS_MAP@ -->

  <servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/my-servlet</url-pattern>
  </servlet-mapping>

, @JSPS_MAP@ .

<loadfile
  property="generated.web.xml.fragment"
  srcFile="${generated.fragment.file}"
/>

<copy file="${orig-web-content.dir}/WEB-INF/web.xml"
  toFile="${generated-web-content.dir}/WEB-INF/web.xml"
>
  <filterset>
    <filter token="JSPS_MAP"
      value=" --&gt; ${generated.web.xml.fragment} &lt;!-- "
    />
  </filterset>
</copy>

, web.xml ( ), , .

, DEV ${orig-web-content.dir}/WEB-INF/web.xml ${generated-web-content.dir}/WEB-INF/web.xml .

+4

jasper2 ant, . , , .

cactus webxmlmerge ant, org.codehaus.cargo.module.webapp.WebXmlMerger

JAXB web.xml; Sebastien Dionne dtd-schemas-generator demo . , .

fwiw, , , ant XSLT.

+1

web.xml, , , , addWebXmlMappings . : <! - JSPC → <! - JSPC → web.xml ! ( org.apcahe.jasper.JspC, , )

+1

All Articles