Bug 11891 - JspC does not work for webapps
Summary: JspC does not work for webapps
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 4
Classification: Unclassified
Component: Jasper 2 (show other bugs)
Version: 4.1.9
Hardware: Other other
: P3 major with 35 votes (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-08-21 10:28 UTC by Greg Wilkins
Modified: 2004-11-16 19:05 UTC (History)
4 users (show)



Attachments
diff of JspCompilationContext.java (497 bytes, patch)
2002-08-21 12:53 UTC, John Trollinger
Details | Diff
diff JspC.java (3.00 KB, patch)
2002-08-21 12:53 UTC, John Trollinger
Details | Diff
diff messages.properties (628 bytes, patch)
2002-08-21 12:54 UTC, John Trollinger
Details | Diff
this patch should replace the first one (forgot a piece) (3.58 KB, patch)
2002-08-21 13:21 UTC, John Trollinger
Details | Diff
Webapp that demonstrates the -webinc problem (3.66 KB, application/java-archive)
2002-08-21 15:31 UTC, Greg Wilkins
Details
jspdemo before JspC generation (1.55 KB, application/zip)
2002-08-29 10:46 UTC, Greg Wilkins
Details
jspdemo after JspC generation (4.00 KB, application/zip)
2002-08-29 10:46 UTC, Greg Wilkins
Details
Contributed patch for this problem. (2.62 KB, patch)
2002-09-03 14:49 UTC, Greg Wilkins
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Greg Wilkins 2002-08-21 10:28:37 UTC
I have tried this for jasper2 from the 4_1_9 tag and from cvs head (2002/08/21).

For a simple webapp with JSPs in subdirectories, a command like:
  java org.apache.jasper.JspC -d gensrc -webapp webapp

creates all the java files in the top directory of gensrc.  Any subdirectories
in the webapp are created - but they are all empty.  If you have index.jsp in
each subdirectory - then you only get a single index.jsp in the top level of gensrc.


For a more complex webapp, the name mungling gets totally confused.  I have not
been able to reproduce this on a small simple webapp - so these reports are
for my real webapp.    Using the same JspC command line about I get the
following error message:

2002-08-21 11:24:38 - The file argument
'/home/gregw/Clients/Cisco/vob/ssd.icotton-GRWILKIN/nwsp/webapp/wap/pages/accountLogon.jsp'
does not exist
error:/home/gregw/Clients/Cisco/vob/ssd.icotton-GRWILKIN/nwsp/webapp/wap/pages/accountLogon.jsp

However that file does exist.

More over if I look in the gensrc directory it has created an empty directory 
called:

gensrc/home/gregw/Clients/Cisco/vob/ssd.icotton-GRWILKIN/nwsp/webapp/wap/pages

Somehow it has got the absolute file path of the webapp
/home/gregw/Clients/Cisco/vob/ssd.icotton-GRWILKIN/nwsp/webapp into the package
path?    

I have tried running JspC with default paths and absolute paths.  Same results.
Comment 1 John Trollinger 2002-08-21 11:08:56 UTC
I have fixed some of this and am making sure I have not broken anything in the 
process.  I will send a patch today or tomorrow.
Comment 2 John Trollinger 2002-08-21 12:53:17 UTC
Created attachment 2789 [details]
diff of JspCompilationContext.java
Comment 3 John Trollinger 2002-08-21 12:53:43 UTC
Created attachment 2790 [details]
diff JspC.java
Comment 4 John Trollinger 2002-08-21 12:54:08 UTC
Created attachment 2791 [details]
diff messages.properties
Comment 5 John Trollinger 2002-08-21 12:58:57 UTC
this patch should fix the generation of the source files in the right 
directories as well as putting the compiled classes in those same directories.

it also changes the class name generation a bit (it no longer escapes '_')

the compiled classes should show up in the same place they would if you went to 
the page directly.

also I added 2 new flags -l to list the errors (this will continue to compile 
even when a compile error is found) I added this to skip over directive include 
files that wont compile and -s to show successful compile messages (these are 
sent to the static log var) I also added a method to allow the change of the 
static log var

please let me know if this solves your problems (or causes any new ones).
Comment 6 John Trollinger 2002-08-21 13:21:52 UTC
Created attachment 2792 [details]
this patch should replace the first one (forgot a piece)
Comment 7 John Trollinger 2002-08-21 13:23:05 UTC
the 4th patch is a replacement for the first JspC.java patch.. sorry about the 
confusion I know I am going to cause.. :-)
Comment 8 Greg Wilkins 2002-08-21 14:04:43 UTC
Thanks for the rapid response.

Well those patches make it a bit better.... Files are being generated in the
right place now.   But if you include a -webinc flag you still get all the
servlets called the same thing.  eg you get lots of servlets defined as
org.apache.jsp.index_jsp


and in my complex webapp, I still get 

2002-08-21 03:02:53 - The file argument
'/home/gregw/Clients/Cisco/vob/ssd.icotton-GRWILKIN/nwsp/webapp/wap/pages/accountLogon.jsp'
does not exist
error:/home/gregw/Clients/Cisco/vob/ssd.icotton-GRWILKIN/nwsp/webapp/wap/pages/accountLogon.jsp


I'll try and reproduce in a simple webapp, but this will take me another day or two.
Comment 9 John Trollinger 2002-08-21 14:29:14 UTC
I can not reproduce your problem with the -webinc flag.  It all works fine for 
me, did you try it with something simple or your big app?

thanks,
John
Comment 10 Greg Wilkins 2002-08-21 15:01:38 UTC
For a simple webapp, ls -R :

webapp/:
CVS/  WEB-INF/  date.jsp  hello.jsp  hello2.jsp  subdir/

webapp/CVS:
Entries  Repository  Root

webapp/WEB-INF:
CVS/  jsp.xml  web.xml

webapp/WEB-INF/CVS:
Entries  Repository  Root

webapp/subdir:
date2.jsp  hello.jsp  hello3.jsp  hello4.jsp  subsubdir/

webapp/subdir/subsubdir:
hello.jsp  hello5.jsp



I run java org.apache.jasper.JspC -d gensrc -webapp webapp -webinc jsp.xml
and jsp.xml ends up with three definitions of
 
       <servlet>
                <servlet-name>org.apache.jsp.hello_jsp</servlet-name>
                <servlet-class>org.apache.jsp.hello_jsp</servlet-class>
        </servlet>


In fact all the package names are org.apache.jsp even in the generated
source code:
gensrc/date_jsp.java:package org.apache.jsp;
gensrc/hello_jsp.java:package org.apache.jsp;
gensrc/hello2_jsp.java:package org.apache.jsp;
gensrc/subdir/hello4_jsp.java:package org.apache.jsp;
gensrc/subdir/hello3_jsp.java:package org.apache.jsp;
gensrc/subdir/date2_jsp.java:package org.apache.jsp;
gensrc/subdir/hello_jsp.java:package org.apache.jsp;
gensrc/subdir/subsubdir/hello5_jsp.java:package org.apache.jsp;
gensrc/subdir/subsubdir/hello_jsp.java:package org.apache.jsp;


Maybe I did not apply the patches correctly???
Tell me when they are in CVS and I'll do an update and try again.








Comment 11 John Trollinger 2002-08-21 15:22:45 UTC
the package names will always be org.apache.jsp (unless you specify other wise 
with the -p option.  Can you attach your sample war file, as I have the same 
simple type of setup and it works fine for me. 



I get this 
	<servlet>
		<servlet-name>org.apache.jsp.index_jsp</servlet-name>
		<servlet-class>org.apache.jsp.index_jsp</servlet-class>
	</servlet>

	<servlet>
		<servlet-name>org.apache.jsp.john_is_cool1_jsp</servlet-name>
		<servlet-class>org.apache.jsp.john_is_cool1_jsp</servlet-class>
	</servlet>

	<servlet>
		<servlet-name>org.apache.jsp.heather_is_cool1_jsp</servlet-name>
		<servlet-class>org.apache.jsp.heather_is_cool1_jsp</servlet-
class>
	</servlet>

	<servlet>
		<servlet-name>org.apache.jsp.heather_is_cool2_jsp</servlet-name>
		<servlet-class>org.apache.jsp.heather_is_cool2_jsp</servlet-
class>
	</servlet>

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

	<servlet-mapping>
		<servlet-name>org.apache.jsp.john_is_cool1_jsp</servlet-name>
		<url-pattern>/john/john_is_cool1.jsp</url-pattern>
	</servlet-mapping>

	<servlet-mapping>
		<servlet-name>org.apache.jsp.heather_is_cool1_jsp</servlet-name>
		<url-pattern>/john/heather/heather_is_cool1.jsp</url-pattern>
	</servlet-mapping>

	<servlet-mapping>
		<servlet-name>org.apache.jsp.heather_is_cool2_jsp</servlet-name>
		<url-pattern>/john/heather/heather_is_cool2.jsp</url-pattern>
	</servlet-mapping>

The patches are not in CVS yet as I do not have commit privs
Comment 12 Greg Wilkins 2002-08-21 15:31:54 UTC
Created attachment 2793 [details]
Webapp that demonstrates the -webinc problem
Comment 13 Greg Wilkins 2002-08-21 15:36:05 UTC
I've attached a demo webapp.   Are you sure that the packages should all be
org.apache.jsp?   What good is putting the different hello.java classes in
different directories in gensrc if they are all going to endup in the same
classfile?

Jasper 1 generated package names matching the gensrc directories:

        <servlet>
                <servlet-name>date</servlet-name>
                <servlet-class>date</servlet-class>
        </servlet>

        <servlet>
                <servlet-name>hello</servlet-name>
                <servlet-class>hello</servlet-class>
        </servlet>

        <servlet>
                <servlet-name>subdir.date2</servlet-name>
                <servlet-class>subdir.date2</servlet-class>
        </servlet>

        <servlet>
                <servlet-name>subdir.hello</servlet-name>
                <servlet-class>subdir.hello</servlet-class>
        </servlet>

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

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

        <servlet-mapping>
                <servlet-name>subdir.date2</servlet-name>
                <url-pattern>/subdir/date2.jsp</url-pattern>
        </servlet-mapping>

        <servlet-mapping>
                <servlet-name>subdir.hello</servlet-name>
                <url-pattern>/subdir/hello.jsp</url-pattern>
        </servlet-mapping>

Comment 14 John Trollinger 2002-08-21 15:44:18 UTC
Your sample works fine for me.  Make sure you applied the patchs correctly.
Comment 15 John Trollinger 2002-08-21 15:51:34 UTC
Yes org.apache.jsp is ok for all the package names.  If you run the webapp you 
will see that despite the fact that the classes are both 
org.apache.jsp.Hello_jsp that if you make the jsp pages different it will work 
fine.  
Comment 16 Greg Wilkins 2002-08-21 15:57:12 UTC
The diffs look to have been applied OK?  It may be some other difference in our
base versions.      I've rolled back to the old jasper for now - because nothing
works for the big webapp and I can't make a small redproducable test case yet.

So if you think you have fixed the directory issue with your patches - you may
as well mark this issue as closed and submit your patches to the tree.

I'll sync with CVS next week and try again when I have more time.

thanks for your help.
Comment 17 Greg Wilkins 2002-08-21 16:24:00 UTC
Just another note on the packages.  While having two different classes
called org.apache.jsp.Hello_jsp may be OK in tomcat, it certainly is not
OK in Jetty

When I compile the two different classes I end up with two different 
org/apache/jsp/Hello_jsp.class files.    I have no where to put these
so that they can be loaded.   I normally moved the compiled class files
to WEB-INF/classes - but I can't if both classes are named the same thing.

So I can't even get to the stage of running this, as I know I have nowhere to
put the two classes.

Are you really really sure that you are running the precompile version and not
just compiling on the fly.  Can you remove the jsp files from your webapp and
still see different content for both the Hello files?

Comment 18 John Trollinger 2002-08-21 17:27:10 UTC
Yes, they are running the different classes and not rebuilding them.  How this 
does this I do know know, but if you post to tomcat-dev they might be able to 
explain.

the JSP spec says the following

"The JSP Page implementation object belongs to an implementation-dependent
named package. The package used may vary between one JSP and another, so
minimal assumptions should be made."

from this statement the spec allows the same package name (or different ones) 
and it is dependent upon the provider (ie tomcat or jetty) I do not know how 
jetty does its packaging.
Comment 19 Greg Wilkins 2002-08-21 17:58:41 UTC
Sorry to go on about this....  Firstly can you send me the jsp.xml file
and an ls -R of the gensrc you get - so we can verify that it is working
the same for both of us.

For what I'm getting generated, I cannot see how any container 
can run the generated xml (I'm on the servlet JSR panel - so you would hope
that I know :-)
 
       <servlet>
                <servlet-name>org.apache.jsp.hello_jsp</servlet-name>
                <servlet-class>org.apache.jsp.hello_jsp</servlet-class>
        </servlet>
        <servlet>
                <servlet-name>org.apache.jsp.hello_jsp</servlet-name>
                <servlet-class>org.apache.jsp.hello_jsp</servlet-class>
        </servlet>

        <servlet-mapping>
                <servlet-name>org.apache.jsp.hello_jsp</servlet-name>
                <url-pattern>/hello.jsp</url-pattern>
        </servlet-mapping>

        <servlet-mapping>
                <servlet-name>org.apache.jsp.hello_jsp</servlet-name>
                <url-pattern>/subdir/hello.jsp</url-pattern>
        </servlet-mapping>

So both hello.jsp servlets have been mapped to a servlet called
org.apache.jsp.hello_jsp

That servlet has been defined twice to be org.apache.jsp.hello_jsp class

So no matter what - the servlet container must serve the same content
for both those hello.jsp files, as they are defined as the same servlet.
Comment 20 Greg Wilkins 2002-08-29 10:41:37 UTC
Sorry but I'm reopening this again as I still cannot make it work for me, and I
now have other users complaining about it.    I will attach new simpler example
of the problem.

I have created a simple webapp called jspdemo:
  jspdemo/: WEB-INF/  index.jsp  subdir/
  jspdemo/WEB-INF: classes/
  jspdemo/WEB-INF/classes: 
  jspdemo/subdir: index.jsp

this is attached as before.zip

I then run 

java org.apache.jasper.JspC -webapp jspdemo -d jspdemo/WEB-INF/classes -webxml
jspdemo/WEB-INF/web.xml

which generates the source and web.xml (after.zip), but they cannot be used
because of two problems.

The source files generated are:
  jspdemo/WEB-INF/classes/index_jsp.java
  jspdemo/WEB-INF/classes/subdir/index_jsp.java

But both are in the org.apache.jsp package. Thus I cannot compile them
to WEB-INF/classes as both end up in 
WEB-INF/classes/org/apache/jsp/index_jsp.class

Also the generated web.xml has a duplicate definition of
        <servlet>
                <servlet-name>org.apache.jsp.index_jsp</servlet-name>
                <servlet-class>org.apache.jsp.index_jsp</servlet-class>
        </servlet>

which is used by both servlet mapping clauses, so both JSPs are mapped
to the same servlet.



 
Comment 21 Greg Wilkins 2002-08-29 10:46:10 UTC
Created attachment 2866 [details]
jspdemo before JspC generation
Comment 22 Greg Wilkins 2002-08-29 10:46:44 UTC
Created attachment 2867 [details]
jspdemo after JspC generation
Comment 23 Greg Wilkins 2002-09-03 14:49:03 UTC
Created attachment 2903 [details]
Contributed patch for this problem.
Comment 24 Greg Wilkins 2002-09-03 14:50:44 UTC
I have attached a patch from noam@violanetworks.com that appears to fix the 
package naming problem.
Comment 25 verysmart 2002-09-09 13:38:29 UTC
I have a fix that modifies the <javac> code by adding a -isolate flag that 
compiles each jsp file in isolation.  If anyone wants it, let me know and I can 
upload it.
Comment 26 Remy Maucherat 2002-09-09 14:42:41 UTC
I also had JspC do the compilation itself, which made the JspC easier to deal 
with (IMHO). Unfortunately, other committers didn't agree, and compilation is 
now a separate operation (which is a bit tricky because of the faked package 
structure).
Comment 27 John Trollinger 2002-09-17 18:28:34 UTC
Is anyone going to add the patch for package names.. as it would realy make a 
lot of other things work nicely (ie ant compiles of JSP pages)
Comment 28 Udo Walker 2002-09-27 15:40:30 UTC
Hi,

I analyzed the problem with jspc and jsp pages in a directory structure.

These are the problems based on the Tomcat 4.1.12 version:

1. the directory structure is copied to place the generated Java files into it. 
But there's a problem with the package names. What are you doing if there's a 
directory or sub-directory with a not legal Java package name, e.g. 'static' or 
'public' etc. so that e.g. a directory name would be /static/public/infopages. 
This should be converted into e.g. '_static/_public/_infopages'.

2. The generated Java file has always the same package (the first line in the 
Java source file). That's by default org.apache.jsp. It should be the converted 
directory structure to a legal package name: for the example above it should be: 
'package _static._public._infopages;'

3. Probably there are also restrictions for a Java class name. Probably some 
characters are not allowd in the class name but are legal for jsp names. These 
should be escaped.

4. The servlet mappings file generator should use all the above used techniques 
to generate a correct mapping. For the above example it should be (with the page 
Test.jsp):

<servlet>
  <servlet-name>_static__public__infopages_Test_jsp</servlet-name>
  <servlet-class>_static._public._infopages.Test_jsp</servlet-class>
</servlet>

<servlet-mapping>
 <servlet-name>_static__public__infopages_Test_jsp</servlet-name>
 <url-pattern>/static/public/infopages/Test.jsp</url-pattern>
</servlet-mapping>

I hope these comments are useful for a correct implementation of the JspC for 
larger web applications with a rich directory structure and jsp names.

With Regards,
Udo Walker


Comment 29 Mark Brodziak 2002-10-16 03:25:41 UTC
I am unclear as to whether this problem is approaching a resolution. I am also 
suffering from the same issue in relation to the lack of class packaging for 
files with the same name. Surely this is a prevalent problem, as a lot of 
people must use 'index.jsp' throughout their directory structure.

The release notes for Tomcat 4.1 ($Id: RELEASE-NOTES-4.1.txt,v 1.21 2002/09/23 
00:32:46 billbarker Exp $) refer to this bug, and indicate the fix as being 
the '-webapp' option. I don't believe that this resolves the issue.

Whilst I can both precompile the classes into .java as well as compile 
into .class using the compile="true" switch, this does not suffice for 
deployment; I am deploying into JBoss 3.0.3 / Tomcat 4.1.12 bundle, and this 
gets translated into the Apache directory structure. Because there are 
several 'org.apache.jsp.index_jsp' class files located within different 
directories in the WEB-INF/classes directory of the WAR file, this confuses the 
class loader and stops deployment.

I believe that instead a fixed package which I believe is currently the case, 
the generated code should contain packages that reflect the JSP directory 
structure such as the following:

/index.jsp 
  Java file: com.my.package.index_jsp
  Generated to: /generated/com/my/package/index_jsp.java
/hello/index.jsp 
  Java file: com.my.package.hello.index_jsp
  Generated to: /generated/com/my/package/hello/index_jsp.java

instead of what currently happens, which is
/index.jsp 
  Java file: com.my.package.index_jsp
  Generated to: /generated/com/my/package/index_jsp.java
/hello/index.jsp 
  Java file: com.my.package.index_jsp
  Generated to: /generated/com/my/package/hello/index_jsp.java

Has somebody already contributed a patch to correctly package the generated 
java source code (and when I say package, I reiterate that I mean 'package xxx' 
within the Java source, not simply by locating the source in a sub-directory)?
Comment 30 Mark Brodziak 2002-10-16 04:58:35 UTC
Greg, I have applied your patch and this has enabled me to proceed 
successfully. It would be great if this could be integrated into the next 
Tomcat release.
Comment 31 Greg Wilkins 2002-10-16 07:58:11 UTC
Mark,
that patch introduced other problems with normal JSP compilation, so 
I have backed it out of my copy of jasper.    Note that I'm not a tomcat
committer and this issue has yet to be assigned to a tomcat developer - so
I don't know if it is being worked on?
Comment 32 Mark Brodziak 2002-10-18 06:53:05 UTC
Greg,

Yes I had the problems with normal JSP compilation as well, and it was due to 
an unchecked cast. Here is the change that resolves it:

JSPCompilationContext.java 145:

boolean isPAckageNeeded= false;
if ( options instanceof JspC )
{
    isPAckageNeeded= ((JspC)options).isOutputDirSet();//if not -dd option
}

I can now precompile and also use standard JSP compilation.
Comment 33 toby cabot 2002-11-18 12:48:15 UTC
The patch attachment dated "09/03/03" along with Mark's notes from 10/18 worked
great with our application (334 jsp's, 8 or so directories).  

Previously we had two issues: if we compiled the whole app in one shot then we
had problems since we have files of the same name in different directories, but
if we compiled the application a directory at a time (setting the package
differently for each one) we had problems since we have one file that gets
included from different directories.
Comment 34 Kin-Man Chung 2003-04-11 23:36:36 UTC
I believe the current 4.1.x has fixed some of the issues and my latest commit in
TC 5 addresses all the issues (it also unifies embedded compilation and jspc). 
try it out and let me know if there are others.  Thnaks.