问题
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:
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.
来源:https://stackoverflow.com/questions/3886530/eclipse-and-how-it-handles-jars-odd-case