利用ant构建 jsp-servlet-class-jar
生活随笔
收集整理的這篇文章主要介紹了
利用ant构建 jsp-servlet-class-jar
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
【0】README
1)本文旨在 給出 利用ant構建 jsp->servlet->class->jar 的分析;
2)本文部分內容轉自:http://zfsn.iteye.com/blog/757919
【1】ant腳本內容 及其分析 1)build.xml <?xml version="1.0" encoding="UTF-8"?> <project name="webNews" basedir="." default="servlet2class"><property file="build.properties" /><target name="all" depends="jsp2servlet,servlet2class,class2jar" /> <target name="help"><echo message="顯示功能列表" /><echo message="jsp2java 通過JspC將JSP轉換成Java源代碼" /><echo message="java2class 將轉換后的Java源代碼進行編譯成class文件" /><echo message="class2jar 將編譯后的class文件打包" /><echo message="clear 清理現場" /></target><target name="jsp2servlet"><taskdef classname="org.apache.jasper.JspC" name="jsp2java"><classpath id="jsp2servlet.classpath"><fileset dir="${tomcat.home}/bin"><include name="*.jar" /></fileset><fileset dir="${tomcat.home}/lib"><include name="*.jar" /></fileset></classpath></taskdef><jsp2javaclasspath="jsp2java.classpath" javaEncoding="UTF-8" validateXml="false" uriroot="${webapp.path}/WebRoot" webXmlFragment="${webapp.path}/WebRoot/WEB-INF/webJSP.xml"webXml="${webapp.path}/WebRoot/WEB-INF/web.xml"outputDir="${webapp.path}/WebRoot/WEB-INF/JspC/src" /></target><target name="servlet2class"><mkdir dir="${webapp.path}/WebRoot/WEB-INF/JspC/classes" /><javac srcdir="${webapp.path}/WebRoot/WEB-INF/JspC/src" destdir="${webapp.path}/Webroot/WEB-INF/JspC/classes" encoding="utf-8" optimize="off" debug="on" failοnerrοr="false" excludes="**/*.smap"><classpath id="java2class.classpath"><fileset dir="${webapp.path}/WebRoot/WEB-INF/lib"><include name="*.jar" /> </fileset><fileset dir="${tomcat.home}/lib"><include name="*.jar" /></fileset><fileset dir="${tomcat.home}/bin"><include name="*.jar" /></fileset><pathelement location="${webapp.path}/WebRoot/WEB-INF/classes" /></classpath></javac></target><target name="class2jar"><!-- <mkdir dir="${webapp.path}/WebRoot/WEB-INF/lib" /> --> <jar jarfile="${webapp.path}/WebRoot/WEB-INF/lib/${webapp.name}JSP.jar" basedir="${webapp.path}/Webroot/WEB-INF/JspC/classes" /></target><target name="clear"><delete dir="${webapp.path}/WebRoot/WEB-INF/JspC/src" /><delete dir="${webapp.path}/Webroot/WEB-INF/JspC/classes" /><delete dir="${webapp.path}/WebRoot/WEB-INF/lib/${webapp.name}JSP.jar"></delete></target> </project> 2)build.properties #tomcat home tomcat.home=D:\\Development\\Tomcat\\apache-tomcat-8.0.36 webapp.path=E:\\bench-cluster\\spring_in_action_eclipse\\precompileJSP webapp.name=precompileJSP 對以上ant 腳本的分析(Analysis) A1)jsp->servlet:(將jsp 轉換為 servlet——特殊的java類) <target name="jsp2servlet"><taskdef classname="org.apache.jasper.JspC" name="jsp2java"><classpath id="jsp2servlet.classpath"><fileset dir="${tomcat.home}/bin"><include name="*.jar" /></fileset><fileset dir="${tomcat.home}/lib"><include name="*.jar" /></fileset></classpath></taskdef><jsp2javaclasspath="jsp2java.classpath" javaEncoding="UTF-8" validateXml="false" uriroot="${webapp.path}/WebRoot" webXmlFragment="${webapp.path}/WebRoot/WEB-INF/webJSP.xml"webXml="${webapp.path}/WebRoot/WEB-INF/web.xml"outputDir="${webapp.path}/WebRoot/WEB-INF/JspC/src" /></target>org.apache.jasper.JspC 的屬性設置,參見 ?https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/jasper/JspC.html;
Attention)注意上述目錄生成的 web.xml, 該文件設置了 servlet 到 uri 的 映射 <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-appPUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd"> <!-- Automatically created by Apache Tomcat JspC. --> <web-app><servlet><servlet-name>org.apache.jsp.home_jsp</servlet-name><servlet-class>org.apache.jsp.home_jsp</servlet-class></servlet><servlet><servlet-name>org.apache.jsp.views.home_jsp</servlet-name><servlet-class>org.apache.jsp.views.home_jsp</servlet-class></servlet><servlet-mapping><servlet-name>org.apache.jsp.home_jsp</servlet-name><url-pattern>/home.jsp</url-pattern></servlet-mapping><servlet-mapping><servlet-name>org.apache.jsp.views.home_jsp</servlet-name><url-pattern>/views/home.jsp</url-pattern></servlet-mapping> </web-app> A2)servlet->class:(將 servlet 文件編譯為 class文件) <target name="servlet2class"><mkdir dir="${webapp.path}/WebRoot/WEB-INF/JspC/classes" /><javac srcdir="${webapp.path}/WebRoot/WEB-INF/JspC/src" destdir="${webapp.path}/Webroot/WEB-INF/JspC/classes" encoding="utf-8" optimize="off" debug="on" failοnerrοr="false" excludes="**/*.smap"><classpath id="java2class.classpath"><fileset dir="${webapp.path}/WebRoot/WEB-INF/lib"><include name="*.jar" /> </fileset><fileset dir="${tomcat.home}/lib"><include name="*.jar" /></fileset><fileset dir="${tomcat.home}/bin"><include name="*.jar" /></fileset><pathelement location="${webapp.path}/WebRoot/WEB-INF/classes" /></classpath></javac></target>
A3)class->jar:(將 上述編譯得到的 class 文件打包為 jar) <target name="class2jar"><!-- <mkdir dir="${webapp.path}/WebRoot/WEB-INF/lib" /> --> <jar jarfile="${webapp.path}/WebRoot/WEB-INF/lib/${webapp.name}JSP.jar" basedir="${webapp.path}/Webroot/WEB-INF/JspC/classes" /></target>
A4)清理臨時文件工作 <target name="clear"><delete dir="${webapp.path}/WebRoot/WEB-INF/JspC/src" /><delete dir="${webapp.path}/Webroot/WEB-INF/JspC/classes" /><delete dir="${webapp.path}/WebRoot/WEB-INF/lib/${webapp.name}JSP.jar"></delete></target>
【2】windows 下執行上述命令的 console info? E:\bench-cluster\spring_in_action_eclipse\precompileJSP>ant jsp2servlet Buildfile: E:\bench-cluster\spring_in_action_eclipse\precompileJSP\build.xmljsp2servlet:[jsp2java] 七月 08, 2016 2:31:24 下午 org.apache.jasper.servlet.TldScanner scanJars[jsp2java] 信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that w ere scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.BUILD SUCCESSFUL Total time: 0 secondsE:\bench-cluster\spring_in_action_eclipse\precompileJSP>ant servlet2class Buildfile: E:\bench-cluster\spring_in_action_eclipse\precompileJSP\build.xmlservlet2class:[mkdir] Created dir: E:\bench-cluster\spring_in_action_eclipse\precompileJSP\WebRoot\WEB-INF\JspC\classes[javac] E:\bench-cluster\spring_in_action_eclipse\precompileJSP\build.xml:45: warning: 'includeantruntime' was not set, defaulting to build.syscla sspath=last; set to false for repeatable builds[javac] Compiling 2 source files to E:\bench-cluster\spring_in_action_eclipse\precompileJSP\Webroot\WEB-INF\JspC\classesBUILD SUCCESSFUL Total time: 0 secondsE:\bench-cluster\spring_in_action_eclipse\precompileJSP>ant class2jar Buildfile: E:\bench-cluster\spring_in_action_eclipse\precompileJSP\build.xmlclass2jar:[jar] Building jar: E:\bench-cluster\spring_in_action_eclipse\precompileJSP\WebRoot\WEB-INF\lib\precompileJSPJSP.jarBUILD SUCCESSFUL Total time: 0 seconds
【1】ant腳本內容 及其分析 1)build.xml <?xml version="1.0" encoding="UTF-8"?> <project name="webNews" basedir="." default="servlet2class"><property file="build.properties" /><target name="all" depends="jsp2servlet,servlet2class,class2jar" /> <target name="help"><echo message="顯示功能列表" /><echo message="jsp2java 通過JspC將JSP轉換成Java源代碼" /><echo message="java2class 將轉換后的Java源代碼進行編譯成class文件" /><echo message="class2jar 將編譯后的class文件打包" /><echo message="clear 清理現場" /></target><target name="jsp2servlet"><taskdef classname="org.apache.jasper.JspC" name="jsp2java"><classpath id="jsp2servlet.classpath"><fileset dir="${tomcat.home}/bin"><include name="*.jar" /></fileset><fileset dir="${tomcat.home}/lib"><include name="*.jar" /></fileset></classpath></taskdef><jsp2javaclasspath="jsp2java.classpath" javaEncoding="UTF-8" validateXml="false" uriroot="${webapp.path}/WebRoot" webXmlFragment="${webapp.path}/WebRoot/WEB-INF/webJSP.xml"webXml="${webapp.path}/WebRoot/WEB-INF/web.xml"outputDir="${webapp.path}/WebRoot/WEB-INF/JspC/src" /></target><target name="servlet2class"><mkdir dir="${webapp.path}/WebRoot/WEB-INF/JspC/classes" /><javac srcdir="${webapp.path}/WebRoot/WEB-INF/JspC/src" destdir="${webapp.path}/Webroot/WEB-INF/JspC/classes" encoding="utf-8" optimize="off" debug="on" failοnerrοr="false" excludes="**/*.smap"><classpath id="java2class.classpath"><fileset dir="${webapp.path}/WebRoot/WEB-INF/lib"><include name="*.jar" /> </fileset><fileset dir="${tomcat.home}/lib"><include name="*.jar" /></fileset><fileset dir="${tomcat.home}/bin"><include name="*.jar" /></fileset><pathelement location="${webapp.path}/WebRoot/WEB-INF/classes" /></classpath></javac></target><target name="class2jar"><!-- <mkdir dir="${webapp.path}/WebRoot/WEB-INF/lib" /> --> <jar jarfile="${webapp.path}/WebRoot/WEB-INF/lib/${webapp.name}JSP.jar" basedir="${webapp.path}/Webroot/WEB-INF/JspC/classes" /></target><target name="clear"><delete dir="${webapp.path}/WebRoot/WEB-INF/JspC/src" /><delete dir="${webapp.path}/Webroot/WEB-INF/JspC/classes" /><delete dir="${webapp.path}/WebRoot/WEB-INF/lib/${webapp.name}JSP.jar"></delete></target> </project> 2)build.properties #tomcat home tomcat.home=D:\\Development\\Tomcat\\apache-tomcat-8.0.36 webapp.path=E:\\bench-cluster\\spring_in_action_eclipse\\precompileJSP webapp.name=precompileJSP 對以上ant 腳本的分析(Analysis) A1)jsp->servlet:(將jsp 轉換為 servlet——特殊的java類) <target name="jsp2servlet"><taskdef classname="org.apache.jasper.JspC" name="jsp2java"><classpath id="jsp2servlet.classpath"><fileset dir="${tomcat.home}/bin"><include name="*.jar" /></fileset><fileset dir="${tomcat.home}/lib"><include name="*.jar" /></fileset></classpath></taskdef><jsp2javaclasspath="jsp2java.classpath" javaEncoding="UTF-8" validateXml="false" uriroot="${webapp.path}/WebRoot" webXmlFragment="${webapp.path}/WebRoot/WEB-INF/webJSP.xml"webXml="${webapp.path}/WebRoot/WEB-INF/web.xml"outputDir="${webapp.path}/WebRoot/WEB-INF/JspC/src" /></target>org.apache.jasper.JspC 的屬性設置,參見 ?https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/jasper/JspC.html;
Attention)注意上述目錄生成的 web.xml, 該文件設置了 servlet 到 uri 的 映射 <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-appPUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN""http://java.sun.com/dtd/web-app_2_3.dtd"> <!-- Automatically created by Apache Tomcat JspC. --> <web-app><servlet><servlet-name>org.apache.jsp.home_jsp</servlet-name><servlet-class>org.apache.jsp.home_jsp</servlet-class></servlet><servlet><servlet-name>org.apache.jsp.views.home_jsp</servlet-name><servlet-class>org.apache.jsp.views.home_jsp</servlet-class></servlet><servlet-mapping><servlet-name>org.apache.jsp.home_jsp</servlet-name><url-pattern>/home.jsp</url-pattern></servlet-mapping><servlet-mapping><servlet-name>org.apache.jsp.views.home_jsp</servlet-name><url-pattern>/views/home.jsp</url-pattern></servlet-mapping> </web-app> A2)servlet->class:(將 servlet 文件編譯為 class文件) <target name="servlet2class"><mkdir dir="${webapp.path}/WebRoot/WEB-INF/JspC/classes" /><javac srcdir="${webapp.path}/WebRoot/WEB-INF/JspC/src" destdir="${webapp.path}/Webroot/WEB-INF/JspC/classes" encoding="utf-8" optimize="off" debug="on" failοnerrοr="false" excludes="**/*.smap"><classpath id="java2class.classpath"><fileset dir="${webapp.path}/WebRoot/WEB-INF/lib"><include name="*.jar" /> </fileset><fileset dir="${tomcat.home}/lib"><include name="*.jar" /></fileset><fileset dir="${tomcat.home}/bin"><include name="*.jar" /></fileset><pathelement location="${webapp.path}/WebRoot/WEB-INF/classes" /></classpath></javac></target>
A3)class->jar:(將 上述編譯得到的 class 文件打包為 jar) <target name="class2jar"><!-- <mkdir dir="${webapp.path}/WebRoot/WEB-INF/lib" /> --> <jar jarfile="${webapp.path}/WebRoot/WEB-INF/lib/${webapp.name}JSP.jar" basedir="${webapp.path}/Webroot/WEB-INF/JspC/classes" /></target>
A4)清理臨時文件工作 <target name="clear"><delete dir="${webapp.path}/WebRoot/WEB-INF/JspC/src" /><delete dir="${webapp.path}/Webroot/WEB-INF/JspC/classes" /><delete dir="${webapp.path}/WebRoot/WEB-INF/lib/${webapp.name}JSP.jar"></delete></target>
【2】windows 下執行上述命令的 console info? E:\bench-cluster\spring_in_action_eclipse\precompileJSP>ant jsp2servlet Buildfile: E:\bench-cluster\spring_in_action_eclipse\precompileJSP\build.xmljsp2servlet:[jsp2java] 七月 08, 2016 2:31:24 下午 org.apache.jasper.servlet.TldScanner scanJars[jsp2java] 信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that w ere scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.BUILD SUCCESSFUL Total time: 0 secondsE:\bench-cluster\spring_in_action_eclipse\precompileJSP>ant servlet2class Buildfile: E:\bench-cluster\spring_in_action_eclipse\precompileJSP\build.xmlservlet2class:[mkdir] Created dir: E:\bench-cluster\spring_in_action_eclipse\precompileJSP\WebRoot\WEB-INF\JspC\classes[javac] E:\bench-cluster\spring_in_action_eclipse\precompileJSP\build.xml:45: warning: 'includeantruntime' was not set, defaulting to build.syscla sspath=last; set to false for repeatable builds[javac] Compiling 2 source files to E:\bench-cluster\spring_in_action_eclipse\precompileJSP\Webroot\WEB-INF\JspC\classesBUILD SUCCESSFUL Total time: 0 secondsE:\bench-cluster\spring_in_action_eclipse\precompileJSP>ant class2jar Buildfile: E:\bench-cluster\spring_in_action_eclipse\precompileJSP\build.xmlclass2jar:[jar] Building jar: E:\bench-cluster\spring_in_action_eclipse\precompileJSP\WebRoot\WEB-INF\lib\precompileJSPJSP.jarBUILD SUCCESSFUL Total time: 0 seconds
總結
以上是生活随笔為你收集整理的利用ant构建 jsp-servlet-class-jar的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 霞最新符文天赋(霞符文2020)
- 下一篇: 电脑的ie浏览器在哪(电脑中的ie浏览器