6

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!

Vikram
  • 3,996
  • 8
  • 37
  • 58
  • 1
    It looks like some kind of sync problem. I assume you already tried clearing your class cache using Project --> clean and refreshed the project using F5. (sync from file system). If none of these work, then I believe there could be some kind of lock in the file system. Check if there are any other programs accessing the same project and if there are any other locks. – uncaught_exceptions Jul 18 '11 at 17:58
  • @doc_180, Thanks a lot for your reply. Actually, the problem was with cleaning the project only. I forgot to clean. ;) – Vikram Jul 20 '11 at 18:32

4 Answers4

11

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.

Aiden Zhao
  • 564
  • 5
  • 24
Nivas
  • 18,126
  • 4
  • 62
  • 76
  • Nivas, thanks a lot. I was only building the workspace and restarting the eclipse. Forgot to clean it. Thanks! – Vikram Jul 18 '11 at 18:07
  • I have actually created a spring boot application from spring tool suit and then imported the project in eclipse. The problem is i have deleted the target folder and `clean` `install` it but still older codes are getting executed. – viper Jun 15 '16 at 06:27
  • @AkashAggarwal can you give more details? The answer above is 5 years old, so it helps if you can let us know what "persists". – Nivas Dec 23 '16 at 15:42
  • @Nivas after battling for a day it turns out that the real problem is with Java not updating the class files. Eclipse wasn't at fault. – Akash Agarwal Dec 23 '16 at 22:31
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>
    
ItamarG3
  • 4,092
  • 6
  • 31
  • 44
ammie1018
  • 21
  • 2
0

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.

Debra
  • 19
  • 1
-1

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.