2012-07-31 73 views
2

我們使用JSPC Ant任務JSP文件預編譯成類類Jetty8 /(再包入戰爭)預編譯的JSP到使用Ant

現在我們切換到碼頭8.據DOC,有存在一個maven插件來做this。我們有螞蟻的任務去做同樣的事嗎?

回答

4

如果您使用jetty發行版附帶的JSP庫,那麼最好。

下面是一個例子,使用碼頭,分佈8.1.5.v20120716

<?xml version="1.0" ?> 
<project name="AntExample1" default="war"> 

    <property name="jetty.home" value="${user.home}/code/intalio/distros/jetty-distribution-8.1.5.v20120716" /> 

    <path id="compile.jspc"> 
     <fileset dir="${jetty.home}"> 
      <include name="lib/servlet-api-*.jar" /> 
      <include name="lib/jsp/*.jar" /> 
     </fileset> 
    </path> 

    <path id="compile.classpath"> 
     <fileset dir="WebContent/WEB-INF/lib"> 
      <include name="*.jar" /> 
     </fileset> 
     <path refid="compile.jspc" /> 
    </path> 

    <target name="jspc" depends="compile"> 
     <taskdef classname="org.apache.jasper.JspC" name="jasper2" classpathref="compile.jspc" /> 
     <jasper2 validateXml="false" 
      uriroot="WebContent" 
      addWebXmlMappings="true" 
      webXmlFragment="WebContent/WEB-INF/generated_web.xml" 
      compilerSourceVM="1.6" 
      compilerTargetVM="1.6" 
      outputDir="build/gen-src" 
      verbose="9" /> 
    </target> 

    <target name="init"> 
     <mkdir dir="build/classes" /> 
     <mkdir dir="build/gen-src" /> 
     <mkdir dir="dist" /> 
     <copy todir="build/gen-src"> 
      <fileset dir="src" includes="**/*.java" /> 
     </copy> 
    </target> 

    <target name="compile" depends="init"> 
     <javac destdir="build/classes" debug="true" srcdir="build/gen-src"> 
      <classpath refid="compile.classpath" /> 
     </javac> 
    </target> 

    <target name="war" depends="jspc"> 
     <war destfile="dist/AntExample.war" webxml="WebContent/WEB-INF/web.xml"> 
      <fileset dir="WebContent" /> 
     <classes dir="build/classes" /> 
     </war> 
    </target> 

    <target name="clean"> 
     <delete dir="dist" /> 
     <delete dir="build" /> 
    </target> 

</project> 

更新:2013年4月8日

推一個例子項目,這個版本到GitHub上。

https://github.com/jetty-project/jetty-example-jspc-ant

+0

@ joakime:我的100點賞金消失得無影無蹤。希望這200點獎金將補償:) – Jayan 2012-08-15 08:02:33

+0

@Jayan賞金並沒有消失,它在星期一到期。 :-) – 2012-08-15 16:36:02

0

從你的第一句話,你顯然已經使用Ant任務預編譯JSP文件...所以使用碼頭 - 8並不意味着你必須改變這一進程的所有,你仍然會像以前一樣進行預編譯,像以前一樣構建war文件,然後部署到jetty-8中。您需要將jsp添加到start.ini中的OPTIONS中,以將jsp引擎放入服務器類加載器中。