Java 代码未正确更新

发布于 2024-11-25 01:05:36 字数 236 浏览 3 评论 0原文

这可能看起来很奇怪。

我用 Java 编写了代码(在 Eclipse 中)。然后,我对代码做了一些修改。现在,我尝试运行新代码(修改后),但它仍然为我提供之前代码的输出。

我在代码中放置了几个调试点,但它跳过了一些调试点(尽管它应该在它们处停止)并在某个调试点处停止,但即使在这里,它也会调用之前代码中存在的方法位置(尽管我现在已经评论过)。从某个地方似乎仍在调试旧代码。

如何摆脱它?

谢谢!

This may seem a weird Q.

I had written a code in Java (in Eclipse). Then, I did some modifications to the code. Now, I am trying to run the new code (modified), but it is still giving me the output which it was giving for the previous code.

I have put few debug points in the code, but it is skipping some of the debug points (though it should stop at them) and stopping at some debug point, but even here it is calling the methods which were present in previous code at that location (though I have commented them now). It seems from somewhere it is still debugging the old code.

How to get rid of it?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

无尽的现实 2024-12-02 01:05:36

您尝试过清理项目吗?

Project(menu) -> clean

还要确保

Project(menu) -> Build Automatically

选中,以便编译您编写的所有新代码

。如果 clean 和 build 不起作用,则可能有一个 jar 文件包含您编辑的类,因此 Eclipse 将运行编译后的类文件在 jar 中而不是当前文件中。

Have you tried cleaning the project?

Project(menu) -> clean

Also make sure

Project(menu) -> Build Automatically

is selected so that all new code you write is compiled then and there

If the clean and build doesn't work, it's possible that there is a jar file contains the class you edited, so the eclipse will run the compiled class file in the jar instead of your current file.

风筝在阴天搁浅。 2024-12-02 01:05:36

java代码未正确更新有两种可能:

  1. 项目->未选中“自动构建”
  2. 在项目 org.eclipse.jdt.core.javabuilder.project 文件中,构建命令被注释或丢失。这里下面提到的一段代码不应被注释:

    ;
         <名称>org.eclipse.jdt.core.javabuilder
         <参数>
    
    

There are two possibilities because of which the java code is not updating properly:

  1. Project -> Build Automatically is not checked
  2. In .project file of Project org.eclipse.jdt.core.javabuilder build command is commented or missing. Here the below mentioned piece of code should not be commented:

    <buildCommand>
         <name>org.eclipse.jdt.core.javabuilder</name>
         <arguments></arguments>
    </buildCommand>
    
☆獨立☆ 2024-12-02 01:05:36

我有同样的问题。我清除了 Eclipse 中打印到控制台的一些代码,但当我从命令行运行代码时,这些更改没有反映出来。我正在从我的代码创建并执行一个 jar 文件。结果我修改后忘记重新编译了。因此,以下问题解决了:

javac packageName/*.java

现在,当我创建 jar 文件时,它将反映更改。

I had the same issue. I cleared out some code in Eclipse that printed to the console but these changes weren't reflected when I ran the code from command line. I am creating and executing a jar file from my code. Turns out I forgot to recompile after I made changes. So the following resolved the issues:

javac packageName/*.java

Now when I create my jar file, it will reflect the changes.

晨曦÷微暖 2024-12-02 01:05:36

就我而言
转到项目属性 -> java构建路径->库

修复了找不到的任何内容(带有红色 x 图标的库)

on my case
go to project properties -> java build path -> libraries

fixed whatever it cannot find (those with the red x icon)

半边脸i 2024-12-02 01:05:36

我最近遇到了这个问题 - 新代码停止工作。我点击 clean - 然后它就找不到主类了,程序根本就不会运行。

我发现的修复(每次都有效)是重构 - 重命名项目。这立即修复了它。然后我就把名字改回来。几天后,这种情况再次发生,我必须再次重命名才能修复它。

I've run into this issue lately - new code stops working. I click clean - then it can't find the main class anymore and the program won't run at all.

The fix I've found (works every time) is refactor - rename the project. This instantly fixes it. Then I just change the name back. Then after a couple days it happens again and I have to rename it again to fix it.

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