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.
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.
Created attachment 2789 [details] diff of JspCompilationContext.java
Created attachment 2790 [details] diff JspC.java
Created attachment 2791 [details] diff messages.properties
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).
Created attachment 2792 [details] this patch should replace the first one (forgot a piece)
the 4th patch is a replacement for the first JspC.java patch.. sorry about the confusion I know I am going to cause.. :-)
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.
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
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.
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
Created attachment 2793 [details] Webapp that demonstrates the -webinc problem
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>
Your sample works fine for me. Make sure you applied the patchs correctly.
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.
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.
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?
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.
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.
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.
Created attachment 2866 [details] jspdemo before JspC generation
Created attachment 2867 [details] jspdemo after JspC generation
Created attachment 2903 [details] Contributed patch for this problem.
I have attached a patch from noam@violanetworks.com that appears to fix the package naming problem.
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.
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).
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)
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
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)?
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.
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?
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.
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.
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.