You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by ut...@spamex.com on 2005/10/06 06:02:48 UTC

precompiling JSPs -- how to resolve references normally resolved by apache?

Hi,

I am trying to get our JSPs to be precompiled as part of
our ant build process to catch all syntax errors at compile
time.

The problem I have run into is that we are using apache +
tomcat and we have set the following rules in apache httpd.
conf:

   JkMount /servlets/* ajp13
   JkMount /jsp/* ajp13
   JkMount /controller/* cont
   JkMount /cgi-bin/java-rmi.cgi ajp13

Inside some of our servlets and JSPs, they refer to other
jsps using the absolute URL "/jsp/" which works in deployed
environment because apache redirects it.  For example, in
one JSP we have  <%@ include file="/jsp/Header.jsp" %>

I setup the tomcat-4.1.30 ant jspc task and it was giving a
NPE. Then I tried the Ant Jspc optional task, and it gave
me an error message:

the file '\Status.jsp' generated the following general
exceptionn: org.apache.jasper.JasperExeption: 
/Status.jsp(3,0) File "/jsp/Header.jsp" not found

Is there any quick and dirty way to get the JspC to resolve
the "/jsp/*.jsp" urls to "*.jsp" or is there no way?

My alternative is to try to change all the "/jsp/*.jsp"
references to "*.jsp" everywhere we do an <%@ include %> or
<jsp:include/> or <jsp:forward/>. I think  that would be ok
since those directices are handled on the tomcat side. Changing
it would be kind of messy since we have a ton of JSPs in a 
large directory hierarchy, so some of those "/jsp/Header.jsp"
references would have to be changed to "../../Header.jsp", etc.
I know I can't get away from the "/jsp" mapping completely
because we have URLs and HTTP redirects which depend on it.

Here is the quick and dirty jspc ant target I created:
 <jspc
     srcdir="${TOP}/web/html/jsp"
     uribase="${TOP}/web/html/jsp"
     uriroot="${TOP}/web/html/jsp"
     destdir="${TMP_DIR}/WEB-INF/src"
     compiler="jasper41"
     verbose="9">
     <include name="*.jsp"/>
     <classpath>
               <!--todo: including all the tomcat jars, overkill i
               know...-->
                <fileset dir="C:\Program Files\Apache Group\Tomcat
                4.1\bin">
                    <include name="*.jar"/>
                </fileset>
                <fileset dir="C:\Program Files\Apache Group\Tomcat
                4.1\common\endorsed">
                    <include name="*.jar"/>
                </fileset>
                <fileset dir="C:\Program Files\Apache Group\Tomcat
                4.1\common\lib">
                    <include name="*.jar"/>
                </fileset>
                <fileset dir="C:\Program Files\Apache Group\Tomcat
                4.1\shared\lib">
                    <include name="*.jar"/>
                </fileset>
                <fileset dir="C:\Program Files\Apache Group\Tomcat
                4.1\server\lib">
                    <include name="*.jar"/>
                </fileset>
                <!-- project classes and external 3rd party jar files
                -->
                <pathelement path="${CLASS_DIR}"/>
                <filelist refid="active.external.jar.filelist"/>
            </classpath>
        </jspc>

Thanks for any advice,
-Alex

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: precompiling JSPs -- how to resolve references normally resolved by apache?

Posted by ut...@spamex.com.
Jon,

Thanks for your help.  The uribase and uriroot were not set correctly.
Here is the final version that I got working. I had one additional twist
that
I needed to copy the JSP files to another location first using the ant
<copy>
task. 
I set uriroot to the webapps root {dir}/html, and then jasper2
automatically
found the JSP files in the subdirectories under jsp/** and correctly
resolved
the references "/jsp/**.jsp" inside the JSP files.

Once it works, it's great. But it several hours of frustration because
tomcat4.x jasper often just print NullPointerExceptions instead of an
error message. So you have to guess what is wrong.

-Alex

    <target name="jspc" depends="init">
        <mkdir dir="${TMP_DIR}/html"/>
        <mkdir dir="${TMP_DIR}/WEB-INF/classes"/>
        <mkdir dir="${TMP_DIR}/WEB-INF/src"/>
        <copy todir="${TMP_DIR}/html"  flatten="false">
            <fileset dir="${TOP}/web/html">
                <include name="jsp/*.jsp"/>
            </fileset>
        </copy>
        <taskdef classname="org.apache.jasper.JspC" name="jasper2" >
            <classpath id="jspc.classpath">
                <fileset
                dir="${BASE_ENG_DIR}/${TOMCAT_DIR}\common\endorsed">
                    <include name="*.jar"/>
                </fileset>
                <fileset dir="${BASE_ENG_DIR}/${TOMCAT_DIR}\common\lib">
                    <include name="*.jar"/>
                </fileset>
                <!-- compiled classes and 3rd party jars -->
                <pathelement path="${CLASS_DIR}"/>
                <filelist refid="active.external.jar.filelist"/>
            </classpath>
        </taskdef>

        <!--<property name="p1" refid="jspc.classpath"/>-->
        <!--<echo>classpath = ${p1}</echo>-->
        <jasper2
            verbose="9"
            compiler="jasper41"
            validateXml="false"
            uriroot="${TMP_DIR}/html"
            webXmlFragment="${TMP_DIR}/WEB-INF/generated_web.xml"
            outputDir="${TMP_DIR}/WEB-INF/src" />
    </target>

    <target name="compile-server-jsps" depends="init,jspc">
        <mkdir dir="${TMP_DIR}/WEB-INF/classes"/>
        <mkdir dir="${TMP_DIR}/WEB-INF/lib"/>

        <javac destdir="${TMP_DIR}/WEB-INF/classes"
               optimize="off"
               failonerror="true"
               srcdir="${TMP_DIR}/WEB-INF/src"
               excludes="**/*.smap"
            >

            <classpath>
                <pathelement location="${TMP_DIR}/WEB-INF/classes"/>
                <path refid="jspc.classpath"/>
            </classpath>
            <include name="**" />
            <exclude name="tags/**" />
        </javac>

    </target>

On Thu, 06 Oct 2005 14:06:23 +0100, "Jon Wingfield"
<jo...@mkodo.com> said:
>
> 
> Unless you have a directory ${TOP}/web/html/jsp/jsp your uribase/uriroot 
> probably aren't right.
> 
> ut9h-3pye@spamex.com wrote:
> > Hi,
> > 
> > I am trying to get our JSPs to be precompiled as part of
> > our ant build process to catch all syntax errors at compile
> > time.
> > 
> > The problem I have run into is that we are using apache +
> > tomcat and we have set the following rules in apache httpd.
> > conf:
> > 
> >    JkMount /servlets/* ajp13
> >    JkMount /jsp/* ajp13
> >    JkMount /controller/* cont
> >    JkMount /cgi-bin/java-rmi.cgi ajp13
> > 
> > Inside some of our servlets and JSPs, they refer to other
> > jsps using the absolute URL "/jsp/" which works in deployed
> > environment because apache redirects it.  For example, in
> > one JSP we have  <%@ include file="/jsp/Header.jsp" %>
> > 
> > I setup the tomcat-4.1.30 ant jspc task and it was giving a
> > NPE. Then I tried the Ant Jspc optional task, and it gave
> > me an error message:
> > 
> > the file '\Status.jsp' generated the following general
> > exceptionn: org.apache.jasper.JasperExeption: 
> > /Status.jsp(3,0) File "/jsp/Header.jsp" not found
> > 
> > Is there any quick and dirty way to get the JspC to resolve
> > the "/jsp/*.jsp" urls to "*.jsp" or is there no way?
> > 
> > My alternative is to try to change all the "/jsp/*.jsp"
> > references to "*.jsp" everywhere we do an <%@ include %> or
> > <jsp:include/> or <jsp:forward/>. I think  that would be ok
> > since those directices are handled on the tomcat side. Changing
> > it would be kind of messy since we have a ton of JSPs in a 
> > large directory hierarchy, so some of those "/jsp/Header.jsp"
> > references would have to be changed to "../../Header.jsp", etc.
> > I know I can't get away from the "/jsp" mapping completely
> > because we have URLs and HTTP redirects which depend on it.
> > 
> > Here is the quick and dirty jspc ant target I created:
> >  <jspc
> >      srcdir="${TOP}/web/html/jsp"
> >      uribase="${TOP}/web/html/jsp"
> >      uriroot="${TOP}/web/html/jsp"
> >      destdir="${TMP_DIR}/WEB-INF/src"
> >      compiler="jasper41"
> >      verbose="9">
> >      <include name="*.jsp"/>
> >      <classpath>
> >                <!--todo: including all the tomcat jars, overkill i
> >                know...-->
> >                 <fileset dir="C:\Program Files\Apache Group\Tomcat
> >                 4.1\bin">
> >                     <include name="*.jar"/>
> >                 </fileset>
> >                 <fileset dir="C:\Program Files\Apache Group\Tomcat
> >                 4.1\common\endorsed">
> >                     <include name="*.jar"/>
> >                 </fileset>
> >                 <fileset dir="C:\Program Files\Apache Group\Tomcat
> >                 4.1\common\lib">
> >                     <include name="*.jar"/>
> >                 </fileset>
> >                 <fileset dir="C:\Program Files\Apache Group\Tomcat
> >                 4.1\shared\lib">
> >                     <include name="*.jar"/>
> >                 </fileset>
> >                 <fileset dir="C:\Program Files\Apache Group\Tomcat
> >                 4.1\server\lib">
> >                     <include name="*.jar"/>
> >                 </fileset>
> >                 <!-- project classes and external 3rd party jar files
> >                 -->
> >                 <pathelement path="${CLASS_DIR}"/>
> >                 <filelist refid="active.external.jar.filelist"/>
> >             </classpath>
> >         </jspc>
> > 
> > Thanks for any advice,
> > -Alex
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: precompiling JSPs -- how to resolve references normally resolved by apache?

Posted by Jon Wingfield <jo...@mkodo.com>.
Unless you have a directory ${TOP}/web/html/jsp/jsp your uribase/uriroot 
probably aren't right.

ut9h-3pye@spamex.com wrote:
> Hi,
> 
> I am trying to get our JSPs to be precompiled as part of
> our ant build process to catch all syntax errors at compile
> time.
> 
> The problem I have run into is that we are using apache +
> tomcat and we have set the following rules in apache httpd.
> conf:
> 
>    JkMount /servlets/* ajp13
>    JkMount /jsp/* ajp13
>    JkMount /controller/* cont
>    JkMount /cgi-bin/java-rmi.cgi ajp13
> 
> Inside some of our servlets and JSPs, they refer to other
> jsps using the absolute URL "/jsp/" which works in deployed
> environment because apache redirects it.  For example, in
> one JSP we have  <%@ include file="/jsp/Header.jsp" %>
> 
> I setup the tomcat-4.1.30 ant jspc task and it was giving a
> NPE. Then I tried the Ant Jspc optional task, and it gave
> me an error message:
> 
> the file '\Status.jsp' generated the following general
> exceptionn: org.apache.jasper.JasperExeption: 
> /Status.jsp(3,0) File "/jsp/Header.jsp" not found
> 
> Is there any quick and dirty way to get the JspC to resolve
> the "/jsp/*.jsp" urls to "*.jsp" or is there no way?
> 
> My alternative is to try to change all the "/jsp/*.jsp"
> references to "*.jsp" everywhere we do an <%@ include %> or
> <jsp:include/> or <jsp:forward/>. I think  that would be ok
> since those directices are handled on the tomcat side. Changing
> it would be kind of messy since we have a ton of JSPs in a 
> large directory hierarchy, so some of those "/jsp/Header.jsp"
> references would have to be changed to "../../Header.jsp", etc.
> I know I can't get away from the "/jsp" mapping completely
> because we have URLs and HTTP redirects which depend on it.
> 
> Here is the quick and dirty jspc ant target I created:
>  <jspc
>      srcdir="${TOP}/web/html/jsp"
>      uribase="${TOP}/web/html/jsp"
>      uriroot="${TOP}/web/html/jsp"
>      destdir="${TMP_DIR}/WEB-INF/src"
>      compiler="jasper41"
>      verbose="9">
>      <include name="*.jsp"/>
>      <classpath>
>                <!--todo: including all the tomcat jars, overkill i
>                know...-->
>                 <fileset dir="C:\Program Files\Apache Group\Tomcat
>                 4.1\bin">
>                     <include name="*.jar"/>
>                 </fileset>
>                 <fileset dir="C:\Program Files\Apache Group\Tomcat
>                 4.1\common\endorsed">
>                     <include name="*.jar"/>
>                 </fileset>
>                 <fileset dir="C:\Program Files\Apache Group\Tomcat
>                 4.1\common\lib">
>                     <include name="*.jar"/>
>                 </fileset>
>                 <fileset dir="C:\Program Files\Apache Group\Tomcat
>                 4.1\shared\lib">
>                     <include name="*.jar"/>
>                 </fileset>
>                 <fileset dir="C:\Program Files\Apache Group\Tomcat
>                 4.1\server\lib">
>                     <include name="*.jar"/>
>                 </fileset>
>                 <!-- project classes and external 3rd party jar files
>                 -->
>                 <pathelement path="${CLASS_DIR}"/>
>                 <filelist refid="active.external.jar.filelist"/>
>             </classpath>
>         </jspc>
> 
> Thanks for any advice,
> -Alex
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org