ant编译JSP
li_cm 2010-08-24 12:19:27 用ant 运行下面的编译,可以将jsp编译为.java,然后再编译为.class,可是运行时会因为jsp页面等代码的错误而停止,大家有什么好的方法
=========================================================
<?xml version= "1.0 " encoding= "iso-8859-1 "?>
<project name= "tomcat precompile " default= "dist " basedir= ". ">
<property name= "tomcat.home " location= "D:\Tomcat "/>
<property name= "ant " location= "D:\Program Files\ant1.5 "/>
<property name= "libpath " location= "E:\JSPPrecompile\lib "/>
<property name= "webapp.name " value= "ischool " />
<property name= "webapp.path " location= "${tomcat.home}/webapps/${webapp.name} "/>
<target name= "jspc ">
<taskdef classname= "org.apache.jasper.JspC " name= "jasper2 " >
<classpath id= "jspc.classpath ">
<pathelement location= "${java.home}/../lib/tools.jar "/>
<fileset dir= "${tomcat.home}/server/lib ">
<include name= "*.jar "/>
</fileset>
<fileset dir= "${tomcat.home}/common/lib ">
<include name= "*.jar "/>
</fileset>
</classpath>
</taskdef>
<taskdef name= "foreach "
classname= "net.sf.antcontrib.logic.ForEach "
classpath= "${ant}/ant-contrib.jar " />
<jasper2
validateXml= "false "
uriroot= "${webapp.path} "
webXmlFragment= "${webapp.path}/WEB-INF/generated_web.xml "
outputDir= "${webapp.path}/WEB-INF/src "
package= "some.unique.string.asd34sad ">
</jasper2>
<replaceregexp match= "^package some.unique.string.asd34sad.*; "
replace= "package org.apache.jsp; "
byline= "true ">
<fileset dir= "${webapp.path}/WEB-INF/src ">
<include name= "**/*.* "/>
</fileset>
</replaceregexp>
<echo> Compiling generated classes from JSPC </echo>
<foreach target= "do-jsp-compile " param= "dir-path ">
<path>
<dirset dir= "${webapp.path}/WEB-INF/src "/>
</path>
</foreach>
<move todir= "${tomcat.home}/work/Standalone/localhost/${webapp.name} ">
<fileset dir= "${webapp.path}/WEB-INF/src ">
<include name= "**/*.* "/>
</fileset>
</move>
</target>
<target name= "do-jsp-compile ">
<echo> Compile JSP in: ${dir-path} </echo>
<javac destdir= "${dir-path} "
optimize= "off "
debug= "on "
failonerror= "false "
srcdir= "${dir-path} "
>
<classpath>
<pathelement location= "${webapp.path}/WEB-INF/classes "/>
<fileset dir= "${webapp.path}/WEB-INF/lib ">
<include name= "*.jar "/>
</fileset>
<pathelement location= "${tomcat.home}/common/classes "/>
<fileset dir= "${tomcat.home}/common/lib ">
<include name= "*.jar "/>
</fileset>
<pathelement location= "${tomcat.home}/shared/classes "/>
<fileset dir= "${tomcat.home}/server/lib ">
<include name= "*.jar "/>
</fileset>
</classpath>
<include name= "*.java " />
</javac>
<mkdir dir= "${dir-path}/org/apache/jsp "/>
<move todir= "${dir-path} " failonerror= "false ">
<fileset dir= "${dir-path}/org/apache/jsp ">
<include name= "*.* "/>
</fileset>
</move>
<delete dir= "${dir-path}/org " failonerror= "false "/>
</target>
<target name= "dist " depends= "jspc " >
</target>
</project>