Java 代码未正确更新
这可能看起来很奇怪。
我用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您尝试过清理项目吗?
还要确保
选中,以便编译您编写的所有新代码
。如果 clean 和 build 不起作用,则可能有一个 jar 文件包含您编辑的类,因此 Eclipse 将运行编译后的类文件在 jar 中而不是当前文件中。
Have you tried cleaning the project?
Also make sure
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.
java代码未正确更新有两种可能:
在项目
org.eclipse.jdt.core.javabuilder
的.project
文件中,构建命令被注释或丢失。这里下面提到的一段代码不应被注释:There are two possibilities because of which the java code is not updating properly:
In
.project
file of Projectorg.eclipse.jdt.core.javabuilder
build command is commented or missing. Here the below mentioned piece of code should not be commented:我有同样的问题。我清除了 Eclipse 中打印到控制台的一些代码,但当我从命令行运行代码时,这些更改没有反映出来。我正在从我的代码创建并执行一个 jar 文件。结果我修改后忘记重新编译了。因此,以下问题解决了:
现在,当我创建 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:
Now when I create my jar file, it will reflect the changes.
就我而言
转到项目属性 -> java构建路径->库
修复了找不到的任何内容(带有红色 x 图标的库)
on my case
go to project properties -> java build path -> libraries
fixed whatever it cannot find (those with the red x icon)
我最近遇到了这个问题 - 新代码停止工作。我点击 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.