Eclipse and How it Handles JARS -- Odd Case
This is a typical case of confusion between build classpath and runtime classpath.
Your build classpath contains references to your Java project (containing the changes to Velocity)... but I bet your runtime classpath holds references to the original Velocity JAR files.
Managing build classpath and runtime classpath in Web projects under Eclipse (the WTP - Web Tools Project) has been going through massive changes over the last few WTP releases. We can guide you through. If you physically added Velocity's JAR files into your WEB-INF/lib
, lets start by removing them.
OK, after you remove the Velocity.jar
file from WEB-INF/lib
, do the following:
- Right-click the project, select "Properties".
- Go to "Java build path". Select the "projects" tab and make sure that your custom Velocity project (lets call it "MyVelocity") is NOT there.
- Still in "Java build path", select the "Libraries" tab and make sure that no Velocity JAR is there either.
By following the steps above, we cleaned your Web-App from any reference whatsoever to MyVelocity (your project) or any other Velocity JAR.
Now comes the fun part. I will instruct you how to correctly "add" Java projects to Web projects as dependencies.
- Still in the project's properties, go to
Deployment Assembly
. - Click "Add".
- Select "Project" and then "Next".
- Select "MyVelocity" and make sure that the "Web Library Reference" checkbox is checked.
- Click "Finish".
Back in the Deployment Assembly
dialog, you should now see MyVelocity
mapped into WEB-INF/lib/MyVelocity.jar
.
Click OK.
What we did by that is to map MyVelocity as a WEB-INF/lib
dependency. By doing that, MyVelocity
is automatically added to the compile-time build-path as well - so it is very important that you don't add it yourself to the build-path, resulting in duplicate build-path entries.
Everything should work for you now. Let me know if you have any problems.
P.S. these instructions are correct if you're developing a stand-alone WAR project; if your WAR file is a part of an EAR, you may wish (under certain circumstances, for example if MyVelocity
is used by other J2EE modules inside the EAR) to map MyVelocity
differently, to a common location; if that's the case, let me know and I'll elaborate further.