0

I use commons-fileupload-1.1.1 and commons-io-1.3.2 to upload/download files in a web application with java 6. In localhost, it runs correctly because I have the 2 jars in my lib (server\default\lib) (I use jboss 4).

When I deploy the application in the server, I have an exception when I try to upload/download files:

java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUploadException

The one difference between localhost and the server is: in the server, I have not the 2 jars.

When I change the classpath of the project and I add the two jars, I deploy the application --> I have the same exception.

Any suggestions?

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
as_taous
  • 113
  • 3
  • 10
  • If the class wasn't in your classpath you'd be getting a `ClassNotFoundException`. You're getting a `NoClassDefFoundError` which is usually misleading. It's probably failing due to an error in a static initializer on another referenced class. – jgitter May 21 '14 at 16:21
  • @jgitter , I think you are inversing the two: http://stackoverflow.com/questions/1457863/what-is-the-difference-between-noclassdeffounderror-and-classnotfoundexception – tom May 22 '14 at 11:05
  • I don't think I am Tom. – jgitter May 22 '14 at 15:44
  • @tom your linked question actually confirms what I said, it just goes more in depth. – jgitter May 22 '14 at 19:40

1 Answers1

1

There are 2 ways of going about this:

  1. Application specific: Add your 2 jars in your project's WEB-INF/lib folder, build your project and deploy.
  2. Alternatively, try the JBOSS_4_AS\server\all\lib folder. That way, all applications deployed in your JBOSS 4 Application server can see the 2 jars.

I hope this helps.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • :I have tested the first solution but it doesn't work (same exception), is it normal ? The second solution work but I want to understand why the first solution doesn't work. – as_taous May 22 '14 at 18:15
  • I have no idea. I don't know if you used the exact same jars to build your project. The `NoClassDefFoundError` means that your code compiled but the class file cannot be found by the `ClassLoader` at runtime. There are various factors and, unless you tell us what jars you used to compile, what JDK version you are compiling with, the JDK version that JBoss AS runs and if there are similar commons fileupload and commons-io jars anywhere in the code or JBoss lib folders, we cannot help for sure. – Buhake Sindi May 22 '14 at 22:52
  • I use java 6 and jboss4. – as_taous Jun 02 '14 at 11:03