0

I followed the steps in BalusC's answer at JSF 2.0 File upload. The only step in which I went differently is the Tomahawk upload link in the answer. The link is broken, so I got tomahawk-1.1.11 from another place. When I try to start Tomcat 7.0.14 from Eclipse I get the following error:

java.lang.NoSuchMethodError: 
javax.servlet.ServletContext.getServletRegistrations()Ljava/util/Map;

And Tomcat doesn't start. Any ideas? Also, the answer in the link is from March. Any developments with file upload in JSF 2?

Community
  • 1
  • 1
Herzog
  • 923
  • 1
  • 14
  • 28
  • One more piece of information: when I go back to version 2.5 in the web.xml file, so that I can work on other areas of the project, I get this error: java.lang.NoClassDefFoundError: Lorg/apache/myfaces/custom/fileupload/UploadedFile; When I'm taking the UploadFile (from the tutorial in the link) out of the project the error goes away. Obviously I'm missing a jar or jars here, but I don't know which one. Any help would be appreciated. – Herzog Nov 27 '11 at 14:00

1 Answers1

0

The /WEB-INF/lib of your web project is cluttered with servletcontainer-specific libraries of a container of a different make/version, such as servlet-api.jar, javaee.jar, etc. Get rid of them.

The mentioned method is introduced in Servlet 3.0 and this error indicates that you've libraries of a Servlet 2.5 container or older in your /WEB-INF/lib. If you have included them to circumvent Eclipse's compilation errors on javax.servlet.* imports, then you should have solved it differently. Namely, by integrating the servletcontainer which you're actually going to use (which is Tomcat 7 in your case) as target runtime in Eclipse and associating the project with it.

Please note that this problem is not related to JSF 2.0. You got an exception pointing to a method of the javax.servlet package, not javax.faces package.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • OK, thanks. I did have a previous servlet-api.jar in the Tomcat's lib. I removed it and now I get this: java.lang.ClassCastException: org.apache.myfaces.renderkit.html.ext.HtmlButtonRenderer cannot be cast to javax.faces.render.Renderer. I assume this means I have the wrong myfaces jar? The one I'm using is myfaces-api-2.1.3.jar and myfaces-impl-2.1.3.jar. Should I use another? Thanks again. – Herzog Nov 27 '11 at 16:12
  • That's part of Tomahawk. This in turn indicates a pollution of classpath with JSF libraries of different versions. It's not clear what JARs you've all placed in the classpath, but to the point you should **never** change the `JRE/lib`, `JRE/lib/ext` and `Tomcat/lib` (unless you know what you're doing). All the JARs specific to your webapp (which are not already been provided by aforementioned libs) needs to go in `/WEB-INF/lib` (and you should not have copies of the libraries which are already been provided by aforementioned libs in `/WEB-INF/lib`). – BalusC Nov 27 '11 at 16:20
  • OK, I removed the myfaces and tomahawk jars from the Tomcat lib. All I have in the classpath now are the myfaces jars: myfaces-impl-2.1.3.jar, myfaces-api-2.1.3., and tomahawk-1.1.0.jar. When I start Tomcat I get this: java.lang.NoClassDefFoundError: Lorg/apache/myfaces/custom/fileupload/UploadedFile, which is used by the Upload Bean you provided. Looks like it's getting closer :) – Herzog Nov 27 '11 at 16:33
  • So... I cleaned up my build path in eclipse and got Tomcat to start. Now I'm hitting the upload.xhtml page but the input tag isn't showing. All I see is the Submit button and this: "Warning: The page /pages/upload.xhtml declares namespace http://myfaces.apache.org/tomahawk and uses the tag t:inputFileUpload , but no TagLibrary associated to namespace." Any help would be appreciated. – Herzog Nov 28 '11 at 10:48
  • You need to install Tomahawk. Put the Tomahawk JAR files in `/WEB-INF/lib`. Absolutely no further configuration is necessary if your Eclipse project is properly setup. – BalusC Nov 28 '11 at 10:54
  • tomahawk-1.1.11 is in my classpath on Eclipse. If I don't also put it in Tomcat's lib, I get the following when trying to go to upload.xhtml: java.lang.NoClassDefFoundError: Lorg/apache/myfaces/custom/fileupload/UploadedFile. When I then go ahead and add it to tomcat's lib, I get the warning from above. What am I doing wrong? – Herzog Nov 28 '11 at 11:19
  • No, you should not manually add them to the build path. Revert your build path to as it is created by Eclipse and do not touch it. You should put the JAR files where your webapp depends on in `/WEB-INF/lib` folder. Eclipse will then automatically take care that the build path is properly set. – BalusC Nov 28 '11 at 11:27
  • Hey, BalusC, is there a way I can contract you for some work on this? I'm loosing one day of work after another here on configuring stuff and I'm beginning to lose heart. (I apologize if I'm breaking any regulations here but I tried looking for a private message button and couldn't find any. – Herzog Nov 28 '11 at 12:26
  • Sorry, no. I suggest to put the project aside and invest some time in following proper books/tutorials on the subject. It'll take some days/weeks. Once you get the proper grasp on the basic concepts, redo your project. – BalusC Nov 28 '11 at 12:29
  • I can't do that. I have a project that needs to be delivered and if I can't do it with JSF, for all its elegance and beauty, I'll just have to go back to struts. Which would really suck. Anyway if you or anyone here feels like helping please contact me at eyal2003@netvision.net.il. – Herzog Nov 28 '11 at 12:35
  • Your problem is caused by a classpath pollution and/or misconfiguration. I've given several hints in the answer and all the comments how it's supposed to be done. You should **not** change the `JRE/lib`, `JRE/lib/ext`, `Tomcat/lib`. Keep them default (reinstall if necessary). You should in Eclipse have a *Dynamic Web Project* which is associated with Tomcat as target container. You should **not** change project's *Build Path* properties. All JARs where webapp depends on should literally be dropped in `/WEB-INF/lib` folder of the project. **No** further JAR/classpath configuration is necessary. – BalusC Nov 28 '11 at 12:39
  • Thanks, BalusC. Ok. I have not touched the JRE or the EAR libraries on the Eclipse project, and I reinstalled Tomcat so that it doesn't have any jars other than those in the distribution. I put all the jars I need in the project's WEB-INF/lib. But I get a bunch of compile errors: the project doesn't see myfaces, hibernate, joda, or jxl. – Herzog Nov 28 '11 at 13:24
  • Apparently it's not been created as a *Dynamic Web Project*. In *Project Facets* of project's properties, check if *Dynamic Web Module* is been set. After all, you should also not manually have created the folder structure with `/WEB-INF/lib` and such if the project was properly setup. – BalusC Nov 28 '11 at 13:28
  • It was set from the start as a dynamic web project but for some reason I didn't have the Web App Libraries in there. I added it through the Configure Build Path but it's reading the jar files from another location and doesn't see what I have in WEB-INF/lib (I didn't create it manually, it was created for me.) So I created a test project and the Web App Libraries are there, but when I drop my jars in there they don't show up in the build path and they don't prevent the compile errors. I really do appreciate that you're hanging in with me on this. – Herzog Nov 28 '11 at 14:52
  • With regard to your test project, do you mean to say that they do not appear when you expand the *Web App Libraries* entry in the *Libraries* tab of the *Build Path* property of the project? – BalusC Nov 28 '11 at 14:54
  • That should not happen. Likely your Eclipse install is broken or there's some plugin which is taking over the library management. What Eclipse version exactly are you using? It's supposed to be at least the full ["Eclipse IDE for Java EE Developers"](http://www.eclipse.org/downloads/) pack. What plugins are you using? A library management tool like Maven for example may require you to do things differently. – BalusC Nov 28 '11 at 15:03
  • I have Helios Service Rlease 2 of the Eclipse Java EE IDE for Web Developers. I have the svn and hibernate plugins and the Android kit, but not much else. Any idea, other than installing a fresh copy in a different location? – Herzog Nov 28 '11 at 15:07
  • I'm not sure. Perhaps you created the project a bit differently or the wrong way, but I can't think of scenarios which would end up the web app libraries not automatically picking up the changes in `/WEB-INF/lib`. It should be already fine with just the default settings in project creation wizard. – BalusC Nov 28 '11 at 15:15
  • I installed the latest release from Eclipse (indigo). I go File > New > Dynamic Web Project, set the Tomcat runtime, take the Wizard's defaults, and click Finish. The Web App Libraries are there in the Java Resources > Libraries, but when I drop jars into WEB-INF/lib they are not picked up. – Herzog Nov 28 '11 at 15:24
  • That's really odd... What operating system platform are you using? Have you created the Eclipse workspace on a local disk or a network disk or some virtual disk? What happens if you rightclick the JAR file which you dropped in `WebContent/WEB-INF/lib` and choose *Build Path > Add to Build Path*? (if that option appears anyway! it's not the proper way, but give it a try) – BalusC Nov 28 '11 at 15:30
  • Or, try to refresh the project manually, this should force Eclipse to scan for changes in the file system where the project is pointing to. Click the project and press F5 (or rightclick it and choose *Refresh*). – BalusC Nov 28 '11 at 15:37
  • Yeah, that did it. They are now there, no compile errors, and Tomcat starts fine. But the upload page still has only the submit button, and this warning: "Warning: The page /pages/upload.xhtml declares namespace http://myfaces.apache.org/tomahawk and uses the tag t:inputFileUpload , but no TagLibrary associated to namespace." Tomahawk 1.1.6 is in my WEB-INF/lib. Can I send you the Tomcat starting log, or any other info? – Herzog Nov 28 '11 at 15:50
  • What exactly did it? Explicitly adding JAR to build path or refreshing the project? As to Tomahawk, you need the one for JSF 2.0. This exist only since 1.1.10, so 1.1.6 is definitely not JSF 2.0 compatible (it has only JSP taglibs, not Facelets/XML taglibs). You can currently get 1.1.11 at http://myfaces.apache.org/tomahawk/download.html (pick the link "MyFaces Tomahawk 1.1.11 for JSF 2.0 (zip)"). – BalusC Nov 28 '11 at 15:53
  • Refreshing the project did it :) I mean I'm slow but I wouldn't go to all this trouble bothering you and than revert to my old way of doing things. I installed Tomahawk 1.1.11 and I am your humble servant-api. It all works!!! – Herzog Nov 28 '11 at 16:14
  • It all works on my windows machine, but when I put it on the Linux staging environment the upload doesn't work, and I get this warning in the log: "t:inputFileUpload requires the current request be intercepted by the filter in order to handle forms with multipart encode type. ExtensionsFilter was initialized but the current request was not intercepted. Please add a filter-mapping entry to intercept jsf page requests." (continuing in the next comment...) – Herzog Dec 25 '11 at 14:56
  • (... continued) Here's the relevant entries in my web.xml: MyFacesExtensionsFilter org.apache.myfaces.webapp.filter.ExtensionsFilter uploadMaxFileSize 50m MyFacesExtensionsFilter Faces Servlet Any ideas how to get this working? – Herzog Dec 25 '11 at 14:57
  • What container is it? Try replacing `` inside `` by an explicit URL pattern mapping such as `*.jsf` or whatever your webapp is using to open JSF pages. – BalusC Dec 25 '11 at 15:46
  • Thanks, BalusC. Looks like the problem started when I added pretty faces, and went away when I removed it. It happens both on my windows dev machine and the linux server. I'll investigate it more and if I can't figure it out I'll post a separate question. – Herzog Dec 26 '11 at 09:48