You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Woodchuck <wo...@yahoo.com> on 2004/06/11 15:13:37 UTC

tomcat 4.1.x jsp pre-compilation

hi,

when i pre-compile my jsps, i found that Tomcat only
likes them when they are compiled with the package
"org.apache.jsp".

if i change the generated *_jsp.java files (before
compiling) to a different package that is anything but
"org.apache.jsp", Tomcat fails to load them when I try
to access the page.

Tomcat (4.1.x) seems to have hard-coded logic inside
to only work with jsp class files packaged under
org.apache.jsp.

has anyone found a workaround for this, so that we are
not restricted to compile all jsp's to the package
org.apache.jsp?

is this a setting/configuration we can tweak on
Tomcat?

thanks in advance!!


	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

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


Re: tomcat 4.1.x jsp pre-compilation

Posted by Woodchuck <wo...@yahoo.com>.
hi Jason,

thx a lot for your reply.  i am, unfortunately, stuck
with Tomcat 4.1.x.

i don't have any problems getting jspc to generate
.java files for jsps that exist in a hierarchical
(sp?) tree.  for instance, my jsps are scattered under
my web root folder, in sub folders, etc..

my problem is that Tomcat 4.1.x only seems to work
with .class files that were compiled into the
"org.apache.jsp" package.  as a result, i have to do
the following round-about deployment:

1)  invoke jspc to generate .java files for all .jsps
2)  modify each resulting .java file to have the
following first line:  package org.apache.jsp;
3)  invoke javac to compile the .java into .class
4)  place .class files into same hierarchy as the
original .jsps

if i were using Tomcat 5 like you were i would only
have to do steps 1 and 3 above and i'm done.

the caveat here is that each .jsp is assumed to have a
unique name.  if not, javac will let you know with a
compile-time error, and you will have to compile
multiple times (each time a subset of unique .java
classes that are outputted to its own folder, then
place every .class file back into respective hierarchy
after all compilation is done).  this is what i'm
seeking to avoid doing.

anyhow, i appreciate your help, but i'm not sure if
it's applicable to my situation.  the jspc compiler
i'm using will automatically take the jsp's location
into account and compute the corresponding package
suffix.


--- Jason Palmatier <co...@yahoo.com> wrote:
> Hi Woodchuck,
> 
> I just fought the exact same thing for two weeks and
> this is what I discovered:
> 
> If you want to precompile all the JSPs with a
> package
> name other than org.apache.jsp you have to use the
> -p
> option and give it a new package name.  This doesn't
> really work, as you may have already discovered,
> especially if you want the subdirectories the JSPs
> exist under to be included in the package name.  To
> get the sub-dirs included I wrote a script to find
> all
> the JSPs under my app's root dir then walked through
> the list and submitted a jspc compile for each of
> the
> JSPs in the list.  I computed the package name based
> on the sub-directory the JSP was found in.  Here's
> the
> main loop I used for my script:
> 
> # Begin Code ---------------------------------
> 
> ALL_JSP_FILES=`find ${WEBAPP_ROOT_DIR}/${PRODUCT}/*
> -name '*.jsp'`
> for i in ${ALL_JSP_FILES}
> do
>    echo "Compiling $i"
> 
>    JSP_FILE=${i##*/}
>    #echo "JSP_FILE = $JSP_FILE"
>   
>    # JSP_DIR is just an intermediate directory that
>    # doesn't need to be passed on to the next 
>    # script (i.e. doesn't need to be exported).
>    JSP_DIR=${i%/*}
>    #echo "JSP_DIR = $JSP_DIR"
> 
>    PRODUCT_SUB_DIR=${JSP_DIR#*/${PRODUCT}}
>    #echo "PRODUCT_SUB_DIR = $PRODUCT_SUB_DIR"
>  
>    # We have to "source" this script in order 
>    # for the exported variables to still be
>    # valid. (i.e. put the . in front of it)
> 
>    . compile_single_jsp.sh
> 
> done 
> 
> # End Code --------------------------------
> 
> The compile_single_jsp.sh converts the
> PRODUCT_SUB_DIR
> variable to a dotted package name suffix using sed:
> 
> PACKAGE_SUFFIX=`echo "$PRODUCT_SUB_DIR" | sed -e
> 's/\//./g'`
> 
> and then calls jspc.sh to do the actual compile:
> 
> jspc.sh \
> -v4 \
> -l \
> -compile \
> -d
>
${TOMCAT_ROOT_DIR}/webapps/${PRODUCT}/WEB-INF/classes
> \
> -p com.mycompany${PACKAGE_SUFFIX} \
> -webinc
>
${TOMCAT_ROOT_DIR}/webapps/${PRODUCT}${PRODUCT_SUB_DIR}/${JSP_FILE}.xml
> \
>
${TOMCAT_ROOT_DIR}/webapps/${PRODUCT}${PRODUCT_SUB_DIR}/${JSP_FILE}
> 
> I run this from the /bin directory in my tomcat
> root. 
> The downside to this is that you then have to merge
> all of the individual web.xml fragments produced by
> each compile into the existing web.xml (or a brand
> new
> one you create).  I wrote another script and then a
> C++ program to do this.
> 
> The only way around this is to use Tomcat 5.x to do
> the compile.  It will automatically compute the
> package name with subdirs though I still had to
> submit
> each by hand to get it to compile beyond my root
> directory (I'm still looking into this).  Of course
> you can't run these compiled JSPs under anything but
> Tomcat 5.x so it's kind of useless if you are stuck
> back at 4.x.  I had to move to 5.x because of a bug
> in
> the 4.x jspc compiler that produced 0 length .java
> files on an compile error but didn't tell you what
> the
> error was.  So currently I use jspc from Tomcat
> 5.0.25
> but still merge all the xml fragments after the
> compiles complete.  It sucks, but the code is
> already
> written so I'm sticking with it until I have time to
> find another way.
> 
> Hope that helps,
> Jason
> 
> --- Woodchuck <wo...@yahoo.com> wrote:
> > hi,
> > 
> > when i pre-compile my jsps, i found that Tomcat
> only
> > likes them when they are compiled with the package
> > "org.apache.jsp".
> > 
> > if i change the generated *_jsp.java files (before
> > compiling) to a different package that is anything
> > but
> > "org.apache.jsp", Tomcat fails to load them when I
> > try
> > to access the page.
> > 
> > Tomcat (4.1.x) seems to have hard-coded logic
> inside
> > to only work with jsp class files packaged under
> > org.apache.jsp.
> > 
> > has anyone found a workaround for this, so that we
> > are
> > not restricted to compile all jsp's to the package
> > org.apache.jsp?
> > 
> > is this a setting/configuration we can tweak on
> > Tomcat?
> > 
> > thanks in advance!!
> > 
> > 
> > 	
> > 		
> > __________________________________
> > Do you Yahoo!?
> > Friends.  Fun.  Try the all-new Yahoo! Messenger.
> > http://messenger.yahoo.com/ 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > tomcat-user-help@jakarta.apache.org
> > 
> 
> 
> 
> 	
> 		
> __________________________________
> Do you Yahoo!?
> Friends.  Fun.  Try the all-new Yahoo! Messenger.
> http://messenger.yahoo.com/ 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tomcat-user-help@jakarta.apache.org
> 



	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

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


Re: tomcat 4.1.x jsp pre-compilation

Posted by Jason Palmatier <co...@yahoo.com>.
Hi Woodchuck,

I just fought the exact same thing for two weeks and
this is what I discovered:

If you want to precompile all the JSPs with a package
name other than org.apache.jsp you have to use the -p
option and give it a new package name.  This doesn't
really work, as you may have already discovered,
especially if you want the subdirectories the JSPs
exist under to be included in the package name.  To
get the sub-dirs included I wrote a script to find all
the JSPs under my app's root dir then walked through
the list and submitted a jspc compile for each of the
JSPs in the list.  I computed the package name based
on the sub-directory the JSP was found in.  Here's the
main loop I used for my script:

# Begin Code ---------------------------------

ALL_JSP_FILES=`find ${WEBAPP_ROOT_DIR}/${PRODUCT}/*
-name '*.jsp'`
for i in ${ALL_JSP_FILES}
do
   echo "Compiling $i"

   JSP_FILE=${i##*/}
   #echo "JSP_FILE = $JSP_FILE"
  
   # JSP_DIR is just an intermediate directory that
   # doesn't need to be passed on to the next 
   # script (i.e. doesn't need to be exported).
   JSP_DIR=${i%/*}
   #echo "JSP_DIR = $JSP_DIR"

   PRODUCT_SUB_DIR=${JSP_DIR#*/${PRODUCT}}
   #echo "PRODUCT_SUB_DIR = $PRODUCT_SUB_DIR"
 
   # We have to "source" this script in order 
   # for the exported variables to still be
   # valid. (i.e. put the . in front of it)

   . compile_single_jsp.sh

done 

# End Code --------------------------------

The compile_single_jsp.sh converts the PRODUCT_SUB_DIR
variable to a dotted package name suffix using sed:

PACKAGE_SUFFIX=`echo "$PRODUCT_SUB_DIR" | sed -e
's/\//./g'`

and then calls jspc.sh to do the actual compile:

jspc.sh \
-v4 \
-l \
-compile \
-d
${TOMCAT_ROOT_DIR}/webapps/${PRODUCT}/WEB-INF/classes
\
-p com.mycompany${PACKAGE_SUFFIX} \
-webinc
${TOMCAT_ROOT_DIR}/webapps/${PRODUCT}${PRODUCT_SUB_DIR}/${JSP_FILE}.xml
\
${TOMCAT_ROOT_DIR}/webapps/${PRODUCT}${PRODUCT_SUB_DIR}/${JSP_FILE}

I run this from the /bin directory in my tomcat root. 
The downside to this is that you then have to merge
all of the individual web.xml fragments produced by
each compile into the existing web.xml (or a brand new
one you create).  I wrote another script and then a
C++ program to do this.

The only way around this is to use Tomcat 5.x to do
the compile.  It will automatically compute the
package name with subdirs though I still had to submit
each by hand to get it to compile beyond my root
directory (I'm still looking into this).  Of course
you can't run these compiled JSPs under anything but
Tomcat 5.x so it's kind of useless if you are stuck
back at 4.x.  I had to move to 5.x because of a bug in
the 4.x jspc compiler that produced 0 length .java
files on an compile error but didn't tell you what the
error was.  So currently I use jspc from Tomcat 5.0.25
but still merge all the xml fragments after the
compiles complete.  It sucks, but the code is already
written so I'm sticking with it until I have time to
find another way.

Hope that helps,
Jason

--- Woodchuck <wo...@yahoo.com> wrote:
> hi,
> 
> when i pre-compile my jsps, i found that Tomcat only
> likes them when they are compiled with the package
> "org.apache.jsp".
> 
> if i change the generated *_jsp.java files (before
> compiling) to a different package that is anything
> but
> "org.apache.jsp", Tomcat fails to load them when I
> try
> to access the page.
> 
> Tomcat (4.1.x) seems to have hard-coded logic inside
> to only work with jsp class files packaged under
> org.apache.jsp.
> 
> has anyone found a workaround for this, so that we
> are
> not restricted to compile all jsp's to the package
> org.apache.jsp?
> 
> is this a setting/configuration we can tweak on
> Tomcat?
> 
> thanks in advance!!
> 
> 
> 	
> 		
> __________________________________
> Do you Yahoo!?
> Friends.  Fun.  Try the all-new Yahoo! Messenger.
> http://messenger.yahoo.com/ 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tomcat-user-help@jakarta.apache.org
> 



	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

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