Friday, December 15, 2006

Version Confusion

I was working on a project that I took over from another developer who left the company I work for when one day I need to work on a bug located in different but related project.

I crank my Eclipse, package the project, deploy it to JBoss 4.0.4 and start debugging. Lo and behold I kept bumping into a strange and initially mysterious problem. This was what I kept bumping into:


HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from
fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception
...
root cause

java.lang.NoSuchMethodError: org.apache.struts.util.RequestUtils.forwardURL(
Ljavax/servlet/http/HttpServletRequest;Lorg/apache/struts/config/ForwardConfig;
Lorg/apache/struts/config/ModuleConfig;)Ljava/lang/String;
...


The thing that surprised me was the fact that the application is in production and should pass this point of failure. I have yet to make any changes to it and I know I have the struts library with all the dependencies in there. I went into the war file and make sure I have them in there. I make sure the manifests define the proper classpaths. So what gives?

To cut the story short, after some checking and experimenting, it dawned on me the possibility that there may be a few conflicting struts.jar (something I initially ruled out). So I went to my current project(package into a different ear file, but deployed into the same server instance), check the libraries, peek to the version info... voila... lo and behold... sure enough that was the problem.

This project that I'm working on, the one I just inherited, uses an ancient version of struts (version 1.1 to be exact) This project, package and deployed along with the other package project (I have multiple ear files deployed, mind you) create such a confusion. The order the packages deployed, my current package with Struts 1.1 was deployed first and apparently got first inline in the classpath and created all these other problems. This is proven, because if I deployed them in different order, it will work. Apparantly because the newer struts.jar is first inline.

Moral of the story: If you have crazy exceptions in which you think you have everything right, go and check to see if you have jar files with different versions in your classpath.