Eclipse 及其如何处理 JARS —— 奇怪的情况

发布于 2024-09-26 18:06:16 字数 536 浏览 6 评论 0原文

尝试对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铁憨憨 2024-10-03 18:06:16

这是构建类路径运行时类路径之间混淆的典型案例。

您的构建类路径包含对您的Java项目的引用(包含对Velocity的更改)...但我敢打赌您的运行时类路径包含对原始Velocity JAR文件的引用。

在 Eclipse 下的 Web 项目(WTP - Web 工具项目)中管理构建类路径运行时类路径在过去的几个 WTP 版本中经历了巨大的变化。我们可以指导您完成。如果您将 Velocity 的 JAR 文件物理添加到 WEB-INF/lib 中,那么我们首先要删除它们。


好的,从 WEB-INF/lib 中删除 Velocity.jar 文件后,请执行以下操作:

  1. 右键单击该项目,选择“属性”。
  2. 转到“Java 构建路径”。选择“项目”选项卡,并确保您的自定义 Velocity 项目(我们称之为“MyVelocity”)在那里。
  3. 仍然在“Java 构建路径”中,选择“库”选项卡并确保那里也没有 Velocity JAR。

通过执行上述步骤,我们清除了您的 Web 应用程序中对 MyVelocity(您的项目)或任何其他 Velocity JAR 的任何引用。

现在来了有趣的部分。我将指导您如何正确地将 Java 项目作为依赖项“添加”到 Web 项目中。

  1. 仍然在项目的属性中,转到部署程序集
  2. 单击“添加”。
  3. 选择“项目”,然后选择“下一步”。
  4. 选择“MyVelocity”并确保选中“Web Library Reference”复选框。
  5. 单击“完成”。

返回“部署程序集”对话框,您现在应该看到映射到 WEB-INF/lib/MyVelocity.jarMyVelocity

单击“确定”。

我们所做的是将 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文