You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rick Fincher <rn...@tbird.com> on 2002/07/31 20:41:46 UTC

JSPC Precompiling Issues and a handy utility

Hi All,

There has been some discussion on here and on the TAGLIBS list about
precompiling JSP's in Tomcat.

To avoid confusion, before I go on I want to point out that there has been a
change in Tomcat 4.1.8 in the naming conventions of servlets generated from
JSP's.

In 4.1.8 a JSP file CATALINA_HOME/webapps/myApp/main.jsp gets compiled into
a servlet  CATALINA_HOME/work/Standalone/localhost/myApp/main_jsp.java.

Prior to 4.1.8 the servlet created was called main$jsp.java.  So they
changed the name convention from $jsp.java to _jsp.java.

I'll use the 4.1.8 names in this post.

Anyway, when I use jspc to precompile I get all the .java files in  , but no
class files.  Does jspc only generate the servlet java files?  The whole
point of precompiling was to prevent javac from being called to compile
those servlets to work around the javac memory leak and speed up page
loading.

Or am I doing something wrong?

I'll list the commands I used below so you can see if I'm doing it right.
Before that though, I did find that calling a JSP page in Tomcat with the
?jsp_precompile argument resulted in the JSP being precompiled and the class
file shows up in CATALINA_HOME/work/Standalone/localhost/myApp.

For example in the browser type
http://myHost.myDomain.com/myApp/main.jsp?jsp_precompile and voila the files
main_jsp.java and main_jsp.class appear in the
CATALINA_HOME/work/Standalone/localhost/myApp directory.

To automate this for entire webapps  Mark Wutka's book "Special Edition
Using Java Server Pages and Servlets" from Que books has a utility program
to look at a webapp on the server and call every JSP file with
?jsp_precompile.

The author has the code on his web site for download at:
http://www.wutka.com/download.shtml.  Select either Windows or Unix format
on this page to download all the examples from his book.

After you unpack this download go into the folder for chapter 10 and look
for Precompile.java.  Compile that program and run it from the command line
with the base URL of the server and the directoryname as parameters, in this
case:

java Precompile http://myHost.myDomain.com myApp

Unfortunately the program is simple and doesn't support SSL so for secure
webApps you'll have to turn off security to precompile or add SSL to the
Precompile.java program.

Now to see what I'm doing wrong.  I'm using Unix so I use jspc.sh instead of
jspc.bat.  The commands I use to call jspc:

I set the CATALINA_HOME environment variables and the JAVA_HOME environment
variable.  I can call java, javac and the other Java utilities.

cd CATALINA_HOME
bin/jspc.sh -webapp webapps/myApp

Jasper campiles all theJSP's in myApp to servlet java files and puts them in
CATALINA_HOME/work/Standalone/localhost/myApp, but no class files get
generated.

Any ideas?

Thanks,

Rick


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


Re: JSPC Precompiling Issues and a handy utility

Posted by Rick Fincher <rn...@tbird.com>.
Hi David,

Thanks for the response.  I'm using an IDE and all it does is spit out a war
file with the JSP sources and WEB-INF.  I guess it can't use class files
because it has no knowlege of the container environment it will be deployed
in.

So it looks like what I need to do is write an ant script (or somethin
similar) to take the webapp name as an argument and:

1. Call jspc.sh with the appropriate parameters to compile the servlets into
the work directory.
2. Pull the common/lib jars  and common/classes into the classpath.
3. Pull the WEB-INF/lib jars and WEB-INF/classes of the webapp into the
class path
4. Call javac with that classpath and compile all the .java files in the
work directory.

A shell script won't work because the classpath is too long for 1024
character limit, unless I use a shell without that restriction.

Rick
----- Original Message -----
snip
>
> The Tomcat JspC process only generates the servlet code.  You have to
compile
> the code yourself.  It's easy enough to set that up as part of your build
> process.
>
> --
> ===================================================================
> David M. Karr          ; Java/J2EE/XML/Unix/C++
> dmkarr@earthlink.net



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


Re: JSPC Precompiling Issues and a handy utility

Posted by "David M. Karr" <dm...@earthlink.net>.
>>>>> "Rick" == Rick Fincher <rn...@tbird.com> writes:

    Rick> Hi All,
    Rick> There has been some discussion on here and on the TAGLIBS list about
    Rick> precompiling JSP's in Tomcat.

    Rick> To avoid confusion, before I go on I want to point out that there has been a
    Rick> change in Tomcat 4.1.8 in the naming conventions of servlets generated from
    Rick> JSP's.

    Rick> In 4.1.8 a JSP file CATALINA_HOME/webapps/myApp/main.jsp gets compiled into
    Rick> a servlet  CATALINA_HOME/work/Standalone/localhost/myApp/main_jsp.java.

    Rick> Prior to 4.1.8 the servlet created was called main$jsp.java.  So they
    Rick> changed the name convention from $jsp.java to _jsp.java.

    Rick> I'll use the 4.1.8 names in this post.

    Rick> Anyway, when I use jspc to precompile I get all the .java files in  , but no
    Rick> class files.  Does jspc only generate the servlet java files?  The whole
    Rick> point of precompiling was to prevent javac from being called to compile
    Rick> those servlets to work around the javac memory leak and speed up page
    Rick> loading.

The Tomcat JspC process only generates the servlet code.  You have to compile
the code yourself.  It's easy enough to set that up as part of your build
process.

-- 
===================================================================
David M. Karr          ; Java/J2EE/XML/Unix/C++
dmkarr@earthlink.net


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


Re: JSPC Precompiling Issues and a handy utility

Posted by adam kramer <ad...@monkey.org>.
On Fri, 2 Aug 2002, Irina Lishchenko wrote:
> This is not the answer but most likely a question, which came in my head
> while I was reading. AFAIK a running server (and server which does not serve
> developers' needs) compiling is made only one time when the server gets the
> request for a certain jsp page. After this compiling each following request
> is served by the server without recompiling (in the case the time of last
> modification of this jsp file is not changed) so javac is not called each
> time when the server gets a request for this page and as follows it does not
> have an influence on the speed of serving user's requests. Do I understand
> something wrong?

  You are correct. After the first request for a page, the JSP page has
been precompiled to a servlet (.java) and that servlet has been compiled
to a java class (.class) by the java compiler. After that, it will not
have to be compiled again (unless you force the reloadable attribute in
your context).
  The problem that was asked about wasn't regarding performance issues but
an issue with the javac compiler. It leaks memory everytime you compile a
JSP page and if you have a large amount of JSPs to be compiled or will be
compiled over time (without restarting the server), it could eventually
cause an out of memory error.

 -adam k.




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


Re: JSPC Precompiling Issues and a handy utility

Posted by Irina Lishchenko <il...@lishchenko.de>.
> Anyway, when I use jspc to precompile I get all the .java files in  , but
> no class files.  Does jspc only generate the servlet java files?  The whole
> point of precompiling was to prevent javac from being called to compile
> those servlets to work around the javac memory leak and speed up page
> loading.
>

This is not the answer but most likely a question, which came in my head 
while I was reading. AFAIK a running server (and server which does not serve 
developers' needs) compiling is made only one time when the server gets the 
request for a certain jsp page. After this compiling each following request 
is served by the server without recompiling (in the case the time of last 
modification of this jsp file is not changed) so javac is not called each 
time when the server gets a request for this page and as follows it does not 
have an influence on the speed of serving user's requests. Do I understand 
something wrong? 

ilis

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