eclipse Java 代码未正确更新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6737105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:38:29  来源:igfitidea点击:

Java Code not properly updating

javaeclipsedebuggingbreakpoints

提问by Vikram

This may seem a weird Q.

这似乎是一个奇怪的 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.

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

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!

谢谢!

回答by Nivas

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.

如果清理和构建不起作用,则可能有一个 jar 文件包含您编辑的类,因此 eclipse 将在 jar 中运行已编译的类文件,而不是您当前的文件。

回答by ammie1018

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

有两种可能,因为 java 代码没有正确更新:

  1. Project -> Build Automatically is not checked
  2. In .projectfile of Project org.eclipse.jdt.core.javabuilderbuild 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>
    
  1. 项目 -> 自动构建未选中
  2. .project项目org.eclipse.jdt.core.javabuilder构建命令的文件中被注释或丢失。这里下面提到的一段代码不应该被注释:

    <buildCommand>
         <name>org.eclipse.jdt.core.javabuilder</name>
         <arguments></arguments>
    </buildCommand>
    

回答by David King

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.

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