When running jasper2 from ant, and there is no web.xml under root/WEB-INF, jasper2 fails with a FileNotFoundException. Since, this worked correctly under 5.5.7, it seems to be a bug. The actual place which causes the problem is in org.apache.jasper.compiler.JspConfig#processWebDotXml(). The code in 5.5.7 was is = ctxt.getResourceAsStream(WEB_XML); if (is == null) { // no web.xml return; } and in 5.5.9, URL uri = ctxt.getResource(WEB_XML); if (uri == null) { // no web.xml return; } ctxt.getResource(WEB_XML) returns a non-null value even if there is no web.xml existing, so ths next uri.openStream() raises a FileNotFoundException.
"ctxt.getResource(WEB_XML) returns a non-null value even if there is no web.xml existing, so ths next uri.openStream() raises a FileNotFoundException." This is incorrect.
I'm sorry, maybe my guess of the reason was wrong. But jasper2 actually raises a FileNotFoundException somewhere, where it did not in 5.5.7. Please check it by yourself. I will show you the stack trace. Some parts are modified, since it includes Japanese messages. [jasper2] java.io.FileNotFoundException: C:\work\harp\web\portal\root\WEB- INF\web.xml (Japanese error message comes here) [jasper2] at java.io.FileInputStream.open(Native Method) [jasper2] at java.io.FileInputStream.<init>(FileInputStream.java:106) [jasper2] at java.io.FileInputStream.<init>(FileInputStream.java:66) [jasper2] at sun.net.www.protocol.file.FileURLConnection.connect (FileURLConnection.java:70) [jasper2] at sun.net.www.protocol.file.FileURLConnection.getInputStream (FileURLConnection.java:161) [jasper2] at java.net.URL.openStream(URL.java:1007) [jasper2] at org.apache.jasper.compiler.JspConfig.processWebDotXml (JspConfig.java:71) [jasper2] at org.apache.jasper.compiler.JspConfig.init (JspConfig.java:197) [jasper2] at org.apache.jasper.compiler.JspConfig.isJspPage (JspConfig.java:361) [jasper2] at org.apache.jasper.JspC.scanFiles(JspC.java:919) [jasper2] at org.apache.jasper.JspC.execute(JspC.java:958) [jasper2] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [jasper2] at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) [jasper2] at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) [jasper2] at java.lang.reflect.Method.invoke(Method.java:585) [jasper2] at org.apache.tools.ant.TaskAdapter.execute (TaskAdapter.java:123) [jasper2] at org.apache.tools.ant.UnknownElement.execute (UnknownElement.java:275) [jasper2] at org.apache.tools.ant.Task.perform(Task.java:364) [jasper2] at org.apache.tools.ant.Target.execute(Target.java:341) [jasper2] at org.apache.tools.ant.Target.performTasks(Target.java:369) [jasper2] at org.apache.tools.ant.Project.executeTarget (Project.java:1214) [jasper2] at org.apache.tools.ant.Project.executeTargets (Project.java:1062) [jasper2] at org.apache.tools.ant.Main.runBuild(Main.java:673) [jasper2] at org.apache.tools.ant.Main.startAnt(Main.java:188) [jasper2] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196) [jasper2] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
As I said, this works for me, and I explicitely tested it. ctxt.getResource(WEB_XML) returns null. Since you insist, I'll leave your bug open, but will ignore it. I recommend you look into this "bug" yourself.
Acrually, no, I didn't test it properly, because you forgot to tell that you were precompiling JSPs (something I just saw by looking at the end of the stack trace right after posting my last reply). If you precompile with jspc, you need to have a web.xml, as all the new servlet declarations will be put there. Otherwise, your precompilation will be useless anyway.
I'm sorry for forgetting to tell you that I was trying to precompile the JSP's. I wrote that I was using ant, so I thought that was enough. > If you precompile with jspc, you need to have a web.xml, as all the new servlet > declarations will be put there. Otherwise, your precompilation will be useless > anyway This is not true. jasper2 has an option called webXmlFragment, which creates part of web.xml, and what we are doing, is joining these webXmlFragments. It worked fine on 5.5.7. Well, I'm working on the code myself now, so I will tell you when I have found a way to fix the problem.
Using jspc means using jspc. Using ant means using ant to compile JSP source. Anyway, look in org.apache.jasper.servlet.JspCServletContext.
Well jasper2 could put jsp directive outside web.xml when pre-compiling : see this ant example: <jasper2 validateXml="false" uriroot="${build.dir}/jspc/myapp" webXmlFragment="${build.dir}/dst/$myapp/WEB-INF/jsp.xml" outputDir="${build.dir}/${wnamei}-src" javaEncoding="ISO-8859-1" trimSpaces="true" /> jasper2 jspc will put the jsp URI in jsp.xml, you could at a later time include in web.xml using <!ENTITY jsp SYSTEM "jsp.xml"> and &jsp.xml; <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" [ <!ENTITY jsp SYSTEM "jsp.xml"> ]> <web-app> .... &jsp; </web-app> Be carefull &jsp; should be in the servlet-mapping area of your web.xml
(In reply to comment #6) > Anyway, look in org.apache.jasper.servlet.JspCServletContext. As you said, I looked at JspCServletContext#getRealPath and JspCServletContext#getResource. They just generates a new URL, and does not check the existents of the actual file. In 5.5.7, getResourceAsStream was used insted of getResource, and the implementation of getResourceAsStream is as below. public InputStream getResourceAsStream(String path) { try { return (getResource(path).openStream()); } catch (Throwable t) { return (null); } } Since Throwable is caught, FileNotFoundException will not be raised to processWebDotXml. Well the easiest way to fix this problem, is modifiy is = uri.openStream(); to try { is = uri.openStream(); } catch (java.io.FileNotFoundException ex) { return; } or maybe catch a Throwable, as it does in getResourceAsStream. I modified JspConfig.java on my local machine as above, and it correctly worked as I wanted.
Created attachment 14728 [details] A patch to catch the Exception raised from uri.openStream() This is a propsed patch for this bug. Just catch Throwable as JspCServletContext#getResourceAsStream does so.
Created attachment 14788 [details] A patch for JspCServletContext#getResource Maybe a better patch. JspCServletContext#getResource returns null if the file is not found.