Java Code not properly updating

2019-02-10 22:06发布

问题:

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!

回答1:

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.



回答2:

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>
    


回答3:

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.