Thursday, June 13, 2013

Tomcat is ignoring changes to struts.xml, other config files and Java class files!

I was taking training on Struts 2, which involved importing some existing "Lab" projects into my Eclipse environment. Everything went smoothly the first time I ran the project, but after making updates and re-running the project, the server would not reflect any of my changes!

For hours, myself and a more senior developer banged our heads trying to figure out this problem. We installed a different version of Tomcat, cleaned the project and the working directory, cleared cache, etc. and nothing worked! From simple outputs to the console in class files, to adding or renaming actions in struts.xml, the project always executed as if it were the first run.

Per usual, the most troubling problem had the simplest solution. The person who originally created the project had the JRE imported from an unusual location. Upon import, I received errors saying java and javax could not be resolved. I hovered over an import statement, and used the "Fix project setup..." option to automatically add Eclipse's default JRE to the build path.

Though it properly added the JRE, it did not remove the old JRE location from the build path. Apparently this can cause some very mysterious behavior... As a last resort we checked the build path, and removed the bad JRE. Problem solved! Everything began functioning as expected.

Noobs using Eclipse Indigo: Right click on the project and select Build Path > Configure Build Path.... Under the Libraries tab, see if you have two JRE libraries. If so, delete the one with the little red X.