views:

33

answers:

1

Trying to make some small changes to Apache's Velocity engine.

Here's what I can and can't do.

I'm making a change to the merge function(). The change I'm making doesn't matter because I haven't made it yet. ;) Right now I am settling for a println statement firing.

I have two references to merge(). If I change the function to mergeBAD() Eclipse tells me that it can't find merge(). Makes sense right? I used to include in my class build path the two jars that you get when downloading velocity but instead I've created a project using the src files provided and used THAT project as a dependency. Again, the fact that is can't find merge() when I rename it to mergeBAD gives me hope.

But when I am running my web server, hit a breakpoint and step into the merge call, it can't find the source! I point it to the project yet again, and it "finds" the source, none of the changes I've made (specifically the println statements) are hit. They are simply skipped over. :(

What on God's green earth could possibly be causing this? It's driving me insane. I've spent the entire day today trying to figure out what's wrong. I can't continue without being able to change Velocity. Exactly what code base is eclipse running the velocity files from?

Many thanks in advance SO! :)

+1  A: 

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:

  1. Right-click the project, select "Properties".
  2. Go to "Java build path". Select the "projects" tab and make sure that your custom Velocity project (lets call it "MyVelocity") is NOT there.
  3. 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.

  1. Still in the project's properties, go to Deployment Assembly.
  2. Click "Add".
  3. Select "Project" and then "Next".
  4. Select "MyVelocity" and make sure that the "Web Library Reference" checkbox is checked.
  5. 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.

Isaac
Snap! :) Heading home for the day but will do this first thing tomorrow!! ^_^
bobber205
I've removed the velocity-1.5.jar that was in my WEB-INF/lib
bobber205
Good. Now verify for us that your WebApp does *not* work. It should fail with a `NoClassDefFoundError`. Once you do that, now is the time to configure your project to include your new, "custom" Velocity Java project inside WEB-INF/lib. I'll edit my initial answer with details how to do that.
Isaac
I cannot find the dialog in the project's properties for "Deployment Assembly". Does this mean I don't have a stand-alone WAR project?
bobber205
I suspect you're using an outdated version of WTP. Make sure you run the latest Eclipse - "Helios" (3.6) should do.
Isaac
I am indeed using the newest version of Eclipse. :)
bobber205
In that case, I suspect your project isn't set up as a "Dynamic Web Project". Right-click the project, go to "Project Facets"; if your project is (as it should be) a Dynamic Web project, you should see "Dynamic Web Module" in the list of facets. Do you?
Isaac