Hi all,

First of all thanks to the guys at codeczar for their plugin. It's really helpful.

I've recently started using the tomcat:jspc goal and I've had a few problems. First of all it fails if I don't declare a maven.war.src directory explicitely in my project.properties. This might be due to the final version of the WAR plugin that I'm using with Maven 1.0 final.

Also, the JSP are translated into Java source code, but there is no target to compile the source code which I find a shame.

Last but not least the
@maven.tomcat.generated@
to be inserted in the web.xml file is not very elegant because if we don't execute the merge, we will end up with an invalid web.xml file. I suggest to use something like this :


<!-- ${maven.tomcat.generated} -->

I have very limited knowledge of Jelly so I'm not sure how I can help do all these changes. I am showing below some goals that do implement all the stuff I've talked about, but they are not integrated with the Tomcat plugin. The following code has been tested with Tomcat 5.0.18 only.

Regards,
  Serge Huber.

project.xml (extract & the same as the Tomcat plugin) :
-------------------------------------------------------
<!-- Dependencies required for JSP precompilation -->
<dependency>
<groupId>tomcat</groupId>
<artifactId>catalina-ant</artifactId>
<version>5.0.18</version>
<properties>
<classloader>root</classloader>
</properties>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-compiler</artifactId>
<version>5.0.18</version>
</dependency>
<dependency>
<groupId>tomcat</groupId>
<artifactId>jasper-runtime</artifactId>
<version>5.0.18</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.3</version>
</dependency>
<!--dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.0</version>
<properties>
<classloader>root</classloader>
</properties>
</dependency-->
<dependency>
<groupId>commons-el</groupId>
<artifactId>commons-el</artifactId>
<version>1.0</version>
<properties>
<classloader>root</classloader>
</properties>
</dependency>
<!--dependency>
<groupId>commons-daemon</groupId>
<artifactId>commons-daemon</artifactId>
<version>SNAPSHOT</version>
<properties>
<classloader>root</classloader>
</properties>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xerces</artifactId>
<version>2.4.0</version>
<properties>
<classloader>root</classloader>
</properties>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.6.2</version>
<properties>
<classloader>root</classloader>
</properties>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xmlParserAPIs</artifactId>
<version>2.2.1</version>
<properties>
<classloader>root</classloader>
</properties>
</dependency-->
<dependency>
<groupId>servletapi</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4-20040521</version>
<!--properties>
<classloader>root</classloader>
</properties-->
<type>jar</type>
</dependency>
<dependency>
<groupId>jspapi</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0-20040521</version>
<!-- don't understand why I need root but throws class not found otherwise -->
<properties>
<classloader>root</classloader>
</properties>
<type>jar</type>
</dependency>



<!--dependency> <groupId>ant</groupId> <artifactId>ant</artifactId> <version>1.6.1</version> <properties> <classloader>root</classloader> </properties> </dependency-->

project.properties :
--------------------
# Set to true if you want JSP precompilation to happen after war:webapp goal
precompile.jsp=true

maven.xml :
-----------
<project default="war"
         xmlns:j="jelly:core"
         xmlns:define="jelly:define"
         xmlns:util="jelly:util"
         xmlns:jasper="jasper"
         xmlns:ant="jelly:ant">

  <!-- ================================================================ -->
  <!-- Deploy to Catalina and Expand                                    -->
  <!-- ================================================================ -->
  <define:taglib uri="jasper">
    <define:jellybean
      name="JspC"
      className="org.apache.jasper.JspC"
      method="execute"
      />
  </define:taglib>

  <preGoal name="war:webapp">
    <j:set var="precompileJsp" value="${precompile.jsp}"/>
    <j:if test="${precompileJsp == 'true'}">
      <attainGoal name="precompile-jsp"/>
    </j:if>
  </preGoal>

<postGoal name="war:webapp">
<j:set var="precompileJsp" value="${precompile.jsp}"/>
<j:if test="${precompileJsp == 'true'}">
<j:set var="target" value="${pom.getPluginContext('maven-war-plugin').getVariable('maven.war.webapp.dir')}"/>
<util:available file="${maven.build.dir}/web-fragment.xml">
<util:loadText var="fragment" file="${maven.build.dir}/web-fragment.xml"/>
<ant:replace file="${target}/WEB-INF/web.xml" token="&lt;!-- ${maven.tomcat.generated} --&gt;" value="${fragment}"/>
</util:available>
</j:if>


  </postGoal>

<goal name="precompile-jsp" description="Precompile all JSPs into java classes, and then into classes" prereqs="war:load,java:compile">
<j:set var="warSource" value="${pom.getPluginContext('maven-war-plugin').getVariable('maven.war.src')}"/>
<ant:mkdir dir="${maven.build.dir}/jspc"/>
<ant:mkdir dir="${maven.build.dir}/jspc-processed"/>
<ant:mkdir dir="${maven.build.dir}/jspc-classes"/>


    <j:set var="jspOutDir" value="${maven.build.dir}/jspc"/>
    <j:set var="jspClassesOutDir" value="${maven.build.dest}"/>
    <ant:path id="jspc.classpath">
      <echo message="Java home=${java.home}" />
      <ant:pathelement location="${java.home}/../lib/tools.jar"/>
      <ant:fileset dir="${tomcat.home}/bin">
        <ant:include name="*.jar"/>
      </ant:fileset>
      <ant:fileset dir="${tomcat.home}/server/lib">
        <ant:include name="*.jar"/>
      </ant:fileset>
      <ant:fileset dir="${tomcat.home}/common/lib">
        <ant:include name="*.jar"/>
      </ant:fileset>
      <ant:path refid="maven.dependency.classpath"/>
      <ant:pathelement path="${maven.build.dest}"/>
    </ant:path>
    <jasper:JspC
      webXmlFragment="${maven.build.dir}/web-fragment.xml"
      package="${pom.package}.jsp.${maven.war.final.name}"
      outputDir="${jspOutDir}"
      srcdir="${warSource}"
      uriroot="${warSource}"
      uribase="/${pom.artifactId}"
      verbose="2"/>
    <ant:javac
      srcdir="${jspOutDir}"
      destdir="${jspClassesOutDir}"
      debug="${maven.compile.debug}"
      deprecation="${maven.compile.deprecation}"
      optimize="${maven.compile.optimize}"
      classpathref="jspc.classpath"/>
  </goal>



- -- --- -----=[ shuber2 at jahia dot com ]=---- --- -- -
www.jahia.org : A collaborative source CMS and Portal Server




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to