Raktim
Raktim

Reputation: 91

java.lang.NoSuchMethodError while uploading file

I am developing an application which has an image upload module. I have written the following code to get multipart form data.

List items = servletFileUpload.parseRequest(request);

I am using commons-fileupload-1.2.1.jar for this purpose. When I am deploying my build on jboss-5.1.0.GA server, it gives an error while uploading any file. The error is as follows:

java.lang.NoSuchMethodError: org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(Lorg/apache/commons/fileupload/RequestContext;)Ljava/util/List; at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126) at com.bworld.action.UploadSubscriptionImage.processRequest(UploadSubscriptionImage.java:46) at com.bworld.action.UploadSubscriptionImage.doPost(UploadSubscriptionImage.java:145) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92) at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126) at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:679)

Can any one please tell me how to recover from this problem?

Upvotes: 4

Views: 8061

Answers (4)

nag
nag

Reputation: 1

use commons-fileupload 1.3.3 version. I used and solved this

Upvotes: 0

Imal Hasaranga Perera
Imal Hasaranga Perera

Reputation: 10029

I know this is an old question but my answer might help someone, this can cause because of few reason

  1. commons file-upload jar might be missing in the your WEB-INF/lib folder as Bonzho mentioned
  2. commons file-upload is shipped with latest tomcat and jboss servers so you need not to use that jar externally in your project. but lets say you have used it, then you can try removing it from the class path and do a clean build, that should most probably work
  3. but sometimes you might still get the error saying java.lang.NoSuchMethodError: that can be happen because of eclipse not showing an error for the older imports that came from the commons-fileupload jar you used so go through the classes of your project and make sure that import statement is either import org.apache.tomcat.util.http.fileupload.* or import org.apache.commons.fileupload* not both

It is always a good practice to use a pom.

Upvotes: 0

Bozho
Bozho

Reputation: 597026

Your commons file-upload jar is missing from your WEB-INF/lib folder OR it is already shipped by JBoss and you should not duplicate it in WEB-INF/lib

Related: http://techblog.bozho.net/?p=866

Upvotes: 1

Woot4Moo
Woot4Moo

Reputation: 24316

You are using the wrong jar. Your classpath is referencing something different than what you think it is. Check your Jboss lib and classpath for jars with a similar name, but different versions. Then do a full clean + build cycle, delete jboss tmp directory, and do a clean + publish on the server. Here is another SO answer

Upvotes: 1

Related Questions