Eclipse 及其如何处理 JARS —— 奇怪的情况
尝试对 Apache 的 Velocity 引擎进行一些小的更改。
这是我能做和不能做的事情。
我正在对合并函数()进行更改。我所做的改变并不重要,因为我还没有做到。 ;) 现在我正在解决 println 语句触发问题。
我有两个对 merge() 的引用。如果我将函数更改为 mergeBAD() Eclipse 会告诉我它找不到 merge()。有道理吧?我曾经在我的类构建路径中包含下载速度时获得的两个 jar,但我使用提供的 src 文件创建了一个项目,并将该项目用作依赖项。同样,当我将其重命名为 mergeBAD 时找不到 merge() 的事实给了我希望。
但是当我运行我的网络服务器时,遇到断点并进入合并调用,它找不到源!我再次将其指向该项目,它“找到”了源代码,我所做的任何更改(特别是 println 语句)都没有被命中。它们只是被跳过。 :(
上帝的绿色地球上可能是什么原因造成的?这让我发疯。我今天花了一整天的时间试图找出问题所在。如果无法更改 Velocity,我就无法继续。到底是什么代码库eclipse 运行速度文件吗?
非常感谢!
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! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是构建类路径和运行时类路径之间混淆的典型案例。
您的构建类路径包含对您的Java项目的引用(包含对Velocity的更改)...但我敢打赌您的运行时类路径包含对原始Velocity JAR文件的引用。
在 Eclipse 下的 Web 项目(WTP - Web 工具项目)中管理构建类路径和运行时类路径在过去的几个 WTP 版本中经历了巨大的变化。我们可以指导您完成。如果您将 Velocity 的 JAR 文件物理添加到
WEB-INF/lib
中,那么我们首先要删除它们。好的,从
WEB-INF/lib
中删除Velocity.jar
文件后,请执行以下操作:通过执行上述步骤,我们清除了您的 Web 应用程序中对 MyVelocity(您的项目)或任何其他 Velocity JAR 的任何引用。
现在来了有趣的部分。我将指导您如何正确地将 Java 项目作为依赖项“添加”到 Web 项目中。
部署程序集
。返回“部署程序集”对话框,您现在应该看到映射到
WEB-INF/lib/MyVelocity.jar
的MyVelocity
。单击“确定”。
我们所做的是将 MyVelocity 映射为
WEB-INF/lib
依赖项。通过这样做,MyVelocity
也会自动添加到编译时构建路径中 - 因此非常重要的是您不要自己将其添加到构建中-路径,导致重复的构建路径条目。现在一切都应该适合你了。如果您有任何问题,请告诉我。
PS:如果您正在开发独立的 WAR 项目,这些说明是正确的;如果您的 WAR 文件是 EAR 的一部分,您可能希望(在某些情况下,例如 EAR 内的其他 J2EE 模块使用
MyVelocity
)映射MyVelocity
以不同的方式,到一个共同的位置;如果是这样,请告诉我,我将进一步详细说明。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 fromWEB-INF/lib
, do the following: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.
Deployment Assembly
.Back in the
Deployment Assembly
dialog, you should now seeMyVelocity
mapped intoWEB-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 mapMyVelocity
differently, to a common location; if that's the case, let me know and I'll elaborate further.