You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christophe Reynaud <cr...@one2team.com> on 2002/04/10 19:35:05 UTC

How to pre-compile JSP's ?

Do you know if there is a simple solution to pre-compile the JSP's ? 
(And
to tell tomcat not to re-compile the JSP's ?)

Thanks

Jay Gardner wrote:

> There are definitely memory leaks in javac. This is a problem when jspc
> compiles your jsp code in the same JVM as the TC server.
>
> --Jay Gardner
>
> -----Original Message-----
> From: Christophe Reynaud [mailto:creynaud@one2team.com]
> Sent: Tuesday, April 09, 2002 12:52 PM
> To: Tomcat Users List
> Subject: Tomcat process takes 246M whereas total java heap is 127M
>
> Hello,
>
> We use tomcat 3.3.1 on Linux RH 7.2.  JVM : IBM 1.3
>
> "top -c" tells that the tomcat threads take 246M but if we use the Java
> function "totalMemory()", it tells that the JVM uses 127M for the heap.
> Where is the rest of memory ?  I expected that the JVM used more than
> only the total of the heap, but in this case it is almost the double !
> Any ideas about the reasons of this problem ?  Are there some momory
> leaks in the JVM ?
>
> Thanks.
>
> Christophe
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>

--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: How to pre-compile JSP's ?

Posted by "Mykola A. Nickishov" <mn...@mn.com.ua>.
"John W. Warner" <jw...@ccs.nrl.navy.mil> writes:

> 1) If you use ANT or can use ant... Put the following in the build
> script.
> <!-- JSPC Precompile -->
> <target name="jspc" depends="init">
>   <java fork="yes" classname="org.apache.jasper.JspC">
>     <arg line="-uriroot /your/Catalina_home/webapps/context -d
>        /your/Catalina_home/WEB-INF/classes -p jsp -webapp
>        /your/Catalina_home/webapps/context" />
>   </java>
> </target>
> (from Jay Gardner's Message 04/08/2002 help with JspC)

Or simply use Ant's jspc optional task.

-- 
/me @ home
MAN-UANIC

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: How to pre-compile JSP's ?

Posted by Sean LeBlanc <se...@nutros.com>.
What is in your init section?
I'm trying to figure out how to do this, too. I'm using Tomcat 4.0.3
on FreeBSD. Is this org.apache.jasper.JspC in Tomcat (Catalina), or is it renamed?
What jar is it in?

Thanks,
Sean

> -----Original Message-----
> From: John W. Warner [mailto:jwarner@ccs.nrl.navy.mil]
> Sent: Wednesday, April 10, 2002 12:30 PM
> To: 'Tomcat Users List'
> Subject: RE: How to pre-compile JSP's ?
> 
> 
> There are three methods. I like #1, I used #3 up until a while ago.
> Anyway, here they are.
> My major criticism of method #3 is that all the machine/port/etc..
> settings should either be passed in on the command line, put in static
> final Strings, or loaded using a properties file. 
> - John
> 
> 1) If you use ANT or can use ant... Put the following in the build
> script.
> <!-- JSPC Precompile -->
> <target name="jspc" depends="init">
>   <java fork="yes" classname="org.apache.jasper.JspC">
>     <arg line="-uriroot /your/Catalina_home/webapps/context -d
>        /your/Catalina_home/WEB-INF/classes -p jsp -webapp
>        /your/Catalina_home/webapps/context" />
>   </java>
> </target>
> (from Jay Gardner's Message 04/08/2002 help with JspC)
> 
> 2) Touch each url for each jsp page and include ?jsp_precompile in the
> url.
> 
> 3) Write a small program to do method 2 for you.
> From Professional JSP Second Edition (wrox) (pretty decent book too,
> simple examples and such)
> <code below this line>
> package com.wrox.projsp.ch03.util;
> 
> import java.io.File;
> import java.io.IOException;
> import java.net.URL;
> 
> public class Precompile {
> 
>   public static void main(String[] args) {
> 
>     String pathname = args[0];
>     String queryString = "?jsp_precompile";
>     String urlBase = "/chapter04/jsp/";
> 
>     try {
>       File dir = new File(pathname);
>       if (!dir.exists()) {
>         throw new IOException("pathname " + pathname + " not found");
>       } 
>       File[] files = dir.listFiles();
>       for (int i = 0; i < files.length; i++) {
>         String jspFile = files[i].getName();
>         if (jspFile.endsWith(".jsp")) {
>           System.out.println("working on " + files[i].getName());
>           try {
>             URL url = new URL("http", "127.0.0.1", 8080, 
>                               urlBase + jspFile + queryString);
>             System.out.println("compiling " + jspFile + " using " +
> urlBase 
>                                + jspFile + queryString);
>             url.getContent();
>           } catch (Exception e) {
> 
>             // add error handling
>           } 
>         } 
>       } 
>     } catch (Exception e) {
>       System.out.println("exception raised:" + e);
>     } 
>   } 
> }
> <code above this line>
> -----Original Message-----
> From: Christophe Reynaud [mailto:creynaud@one2team.com] 
> Sent: Wednesday, April 10, 2002 01:35 PM
> To: Tomcat Users List
> Subject: How to pre-compile JSP's ?
> 
> 
> Do you know if there is a simple solution to pre-compile the JSP's ? 
> (And
> to tell tomcat not to re-compile the JSP's ?)
> 
> Thanks
> 
> Jay Gardner wrote:
> 
> > There are definitely memory leaks in javac. This is a problem when
> jspc
> > compiles your jsp code in the same JVM as the TC server.
> >
> > --Jay Gardner
> >
> > -----Original Message-----
> > From: Christophe Reynaud [mailto:creynaud@one2team.com]
> > Sent: Tuesday, April 09, 2002 12:52 PM
> > To: Tomcat Users List
> > Subject: Tomcat process takes 246M whereas total java heap is 127M
> >
> > Hello,
> >
> > We use tomcat 3.3.1 on Linux RH 7.2.  JVM : IBM 1.3
> >
> > "top -c" tells that the tomcat threads take 246M but if we use the
> Java
> > function "totalMemory()", it tells that the JVM uses 127M for the
> heap.
> > Where is the rest of memory ?  I expected that the JVM used 
> more than
> > only the total of the heap, but in this case it is almost 
> the double !
> > Any ideas about the reasons of this problem ?  Are there some momory
> > leaks in the JVM ?
> >
> > Thanks.
> >
> > Christophe
> >
> > --
> > To unsubscribe:   
<ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>

--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: How to pre-compile JSP's ?

Posted by "John W. Warner" <jw...@ccs.nrl.navy.mil>.
There are three methods. I like #1, I used #3 up until a while ago.
Anyway, here they are.
My major criticism of method #3 is that all the machine/port/etc..
settings should either be passed in on the command line, put in static
final Strings, or loaded using a properties file. 
- John

1) If you use ANT or can use ant... Put the following in the build
script.
<!-- JSPC Precompile -->
<target name="jspc" depends="init">
  <java fork="yes" classname="org.apache.jasper.JspC">
    <arg line="-uriroot /your/Catalina_home/webapps/context -d
       /your/Catalina_home/WEB-INF/classes -p jsp -webapp
       /your/Catalina_home/webapps/context" />
  </java>
</target>
(from Jay Gardner's Message 04/08/2002 help with JspC)

2) Touch each url for each jsp page and include ?jsp_precompile in the
url.

3) Write a small program to do method 2 for you.
>From Professional JSP Second Edition (wrox) (pretty decent book too,
simple examples and such)
<code below this line>
package com.wrox.projsp.ch03.util;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class Precompile {

  public static void main(String[] args) {

    String pathname = args[0];
    String queryString = "?jsp_precompile";
    String urlBase = "/chapter04/jsp/";

    try {
      File dir = new File(pathname);
      if (!dir.exists()) {
        throw new IOException("pathname " + pathname + " not found");
      } 
      File[] files = dir.listFiles();
      for (int i = 0; i < files.length; i++) {
        String jspFile = files[i].getName();
        if (jspFile.endsWith(".jsp")) {
          System.out.println("working on " + files[i].getName());
          try {
            URL url = new URL("http", "127.0.0.1", 8080, 
                              urlBase + jspFile + queryString);
            System.out.println("compiling " + jspFile + " using " +
urlBase 
                               + jspFile + queryString);
            url.getContent();
          } catch (Exception e) {

            // add error handling
          } 
        } 
      } 
    } catch (Exception e) {
      System.out.println("exception raised:" + e);
    } 
  } 
}
<code above this line>
-----Original Message-----
From: Christophe Reynaud [mailto:creynaud@one2team.com] 
Sent: Wednesday, April 10, 2002 01:35 PM
To: Tomcat Users List
Subject: How to pre-compile JSP's ?


Do you know if there is a simple solution to pre-compile the JSP's ? 
(And
to tell tomcat not to re-compile the JSP's ?)

Thanks

Jay Gardner wrote:

> There are definitely memory leaks in javac. This is a problem when
jspc
> compiles your jsp code in the same JVM as the TC server.
>
> --Jay Gardner
>
> -----Original Message-----
> From: Christophe Reynaud [mailto:creynaud@one2team.com]
> Sent: Tuesday, April 09, 2002 12:52 PM
> To: Tomcat Users List
> Subject: Tomcat process takes 246M whereas total java heap is 127M
>
> Hello,
>
> We use tomcat 3.3.1 on Linux RH 7.2.  JVM : IBM 1.3
>
> "top -c" tells that the tomcat threads take 246M but if we use the
Java
> function "totalMemory()", it tells that the JVM uses 127M for the
heap.
> Where is the rest of memory ?  I expected that the JVM used more than
> only the total of the heap, but in this case it is almost the double !
> Any ideas about the reasons of this problem ?  Are there some momory
> leaks in the JVM ?
>
> Thanks.
>
> Christophe
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>

--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: How to pre-compile JSP's ?

Posted by "John W. Warner" <jw...@ccs.nrl.navy.mil>.
As a stepping stone, I'd suggest you remove one or two of your jsps from
the package and try them in stand alone fashion (no package). Then try
adding them back using package jsp; that should help. I've tried your
method with no package for my JSPs and it worked fine. 
- John


-----Original Message-----
From: Jay Gardner [mailto:gjk@qwest.net] 
Sent: Wednesday, April 10, 2002 02:06 PM
To: Tomcat Users List
Subject: RE: How to pre-compile JSP's ?

There is a tool jspc that come with the TC 4.X server that can be used
to
create servlet source for you JSPs. These sources can in turn be
compiled
into .class files. At the same time the jspc tool can create a web.inc
file
that contains all the new servlet mappings. This can be joined with the
web.xml file in the WEB-INF directory so that the servlets will be
mapped to
the jsp urls. My understanding is that these mappings take precedence
and
redirect using the web.xml entries so the jsp source is never used.

I am currently trying to get this to work. I will re-post my problem
below
and maybe???? someone will give us some feedback. Once I get this
working, I
will gladly write up the process and submit it back to the project as
documentation.


REPOST:

I am trying to pre-compile my jsp using jspc.bat on win2K. The reason I
want
to do this is so that JSP code can't be changed on the fly in
production. I
am using TC4.0.3.

Here is how I try to do this from an ANT build script:

    <!-- JSPC:  pre-compile JSPs -->
     <target name="jspc"  depends="init">
          <java fork="yes" classname="org.apache.jasper.JspC">
<arg line="-uriroot d:/jboss/tomcat/webapps/smartjobs -d
d:/jboss/tomcat/webapps/smartjobs/WEB-INF/classes -p jsp -webinc
d:/jboss/tomcat/webapps/smartjobs/WEB-INF/web.inc -webapp
d:/jboss/tomcat/webapps/smartjobs" />
        </java>
    </target>

*********NOTE********** This has the same net result as doing this:

cd %CATALINA_HOME%\bin

jspc.bat -uri d:/jboss/tomcat/webapps/smartjobs -d
d:/jboss/tomcat/webapps/smartjob/WEB-INF/classes -p jsp -webinc
d:/jboss/tomcat/webapps/smartjobs/WEB-INF/web.inc -webapp
d:/jboss/tomcat/webapps/smartjobs


***********************

This does build all of the .java files in
d:/jboss/tomcat/webapps/smartjobs/WEB-INF/classes/jsp, but the package
name
in them is actually as follows:

package jsp.;

It is the dot that is being appended to the end of the package name.
This
same dot has found its way into the web.inc file as well.

<servlet>
                        <servlet-name>jsp..index</servlet-name>
                        <servlet-class>jsp..index</servlet-class>
            </servlet>

            <servlet-mapping>
                        <servlet-name>jsp..index</servlet-name>
                        <url-pattern>/index.jsp</url-pattern>
            </servlet-mapping>

I went and looked at the CommandLineContext class and saw that
getFullClassName() seems to append a . for some reason.

Anyway, has anyone else run into this?? I there something obvious that I
am
doing wrong? Is more info needed before someone can help me?

Thanks in advance!

--Jay Gardner

-----Original Message-----
From: Christophe Reynaud [mailto:creynaud@one2team.com]
Sent: Wednesday, April 10, 2002 11:35 AM
To: Tomcat Users List
Subject: How to pre-compile JSP's ?


Do you know if there is a simple solution to pre-compile the JSP's ?
(And
to tell tomcat not to re-compile the JSP's ?)

Thanks

Jay Gardner wrote:

> There are definitely memory leaks in javac. This is a problem when
jspc
> compiles your jsp code in the same JVM as the TC server.
>
> --Jay Gardner
>
> -----Original Message-----
> From: Christophe Reynaud [mailto:creynaud@one2team.com]
> Sent: Tuesday, April 09, 2002 12:52 PM
> To: Tomcat Users List
> Subject: Tomcat process takes 246M whereas total java heap is 127M
>
> Hello,
>
> We use tomcat 3.3.1 on Linux RH 7.2.  JVM : IBM 1.3
>
> "top -c" tells that the tomcat threads take 246M but if we use the
Java
> function "totalMemory()", it tells that the JVM uses 127M for the
heap.
> Where is the rest of memory ?  I expected that the JVM used more than
> only the total of the heap, but in this case it is almost the double !
> Any ideas about the reasons of this problem ?  Are there some momory
> leaks in the JVM ?
>
> Thanks.
>
> Christophe
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>

--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


RE: How to pre-compile JSP's ?

Posted by Jay Gardner <gj...@qwest.net>.
There is a tool jspc that come with the TC 4.X server that can be used to
create servlet source for you JSPs. These sources can in turn be compiled
into .class files. At the same time the jspc tool can create a web.inc file
that contains all the new servlet mappings. This can be joined with the
web.xml file in the WEB-INF directory so that the servlets will be mapped to
the jsp urls. My understanding is that these mappings take precedence and
redirect using the web.xml entries so the jsp source is never used.

I am currently trying to get this to work. I will re-post my problem below
and maybe???? someone will give us some feedback. Once I get this working, I
will gladly write up the process and submit it back to the project as
documentation.


REPOST:

I am trying to pre-compile my jsp using jspc.bat on win2K. The reason I want
to do this is so that JSP code can't be changed on the fly in production. I
am using TC4.0.3.

Here is how I try to do this from an ANT build script:

    <!-- JSPC:  pre-compile JSPs -->
     <target name="jspc"  depends="init">
          <java fork="yes" classname="org.apache.jasper.JspC">
<arg line="-uriroot d:/jboss/tomcat/webapps/smartjobs -d
d:/jboss/tomcat/webapps/smartjobs/WEB-INF/classes -p jsp -webinc
d:/jboss/tomcat/webapps/smartjobs/WEB-INF/web.inc -webapp
d:/jboss/tomcat/webapps/smartjobs" />
        </java>
    </target>

*********NOTE********** This has the same net result as doing this:

cd %CATALINA_HOME%\bin

jspc.bat -uri d:/jboss/tomcat/webapps/smartjobs -d
d:/jboss/tomcat/webapps/smartjob/WEB-INF/classes -p jsp -webinc
d:/jboss/tomcat/webapps/smartjobs/WEB-INF/web.inc -webapp
d:/jboss/tomcat/webapps/smartjobs


***********************

This does build all of the .java files in
d:/jboss/tomcat/webapps/smartjobs/WEB-INF/classes/jsp, but the package name
in them is actually as follows:

package jsp.;

It is the dot that is being appended to the end of the package name. This
same dot has found its way into the web.inc file as well.

<servlet>
                        <servlet-name>jsp..index</servlet-name>
                        <servlet-class>jsp..index</servlet-class>
            </servlet>

            <servlet-mapping>
                        <servlet-name>jsp..index</servlet-name>
                        <url-pattern>/index.jsp</url-pattern>
            </servlet-mapping>

I went and looked at the CommandLineContext class and saw that
getFullClassName() seems to append a . for some reason.

Anyway, has anyone else run into this?? I there something obvious that I am
doing wrong? Is more info needed before someone can help me?

Thanks in advance!

--Jay Gardner

-----Original Message-----
From: Christophe Reynaud [mailto:creynaud@one2team.com]
Sent: Wednesday, April 10, 2002 11:35 AM
To: Tomcat Users List
Subject: How to pre-compile JSP's ?


Do you know if there is a simple solution to pre-compile the JSP's ?
(And
to tell tomcat not to re-compile the JSP's ?)

Thanks

Jay Gardner wrote:

> There are definitely memory leaks in javac. This is a problem when jspc
> compiles your jsp code in the same JVM as the TC server.
>
> --Jay Gardner
>
> -----Original Message-----
> From: Christophe Reynaud [mailto:creynaud@one2team.com]
> Sent: Tuesday, April 09, 2002 12:52 PM
> To: Tomcat Users List
> Subject: Tomcat process takes 246M whereas total java heap is 127M
>
> Hello,
>
> We use tomcat 3.3.1 on Linux RH 7.2.  JVM : IBM 1.3
>
> "top -c" tells that the tomcat threads take 246M but if we use the Java
> function "totalMemory()", it tells that the JVM uses 127M for the heap.
> Where is the rest of memory ?  I expected that the JVM used more than
> only the total of the heap, but in this case it is almost the double !
> Any ideas about the reasons of this problem ?  Are there some momory
> leaks in the JVM ?
>
> Thanks.
>
> Christophe
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
> --
> To unsubscribe:   <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>

--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>