JavaDeveloper
JavaDeveloper

Reputation: 5660

Why eclipse doesn't recompile last changes made to my Java classes?

I have a simple file with just 1 line that prints "Hello World" inside main. I execute it and it prints "Hello World" on eclipse console. Now when I change the string to "Bye world" it still prints "Hello World". Infact if I cause a syntax error by modifying println to prrrintln. it still prints "Hello World". What can cause eclipse to not use the latest file ? When I try to run it from command line, I get the following error:

bin> java WordBreakProblem.class 
Error: Could not find or load main class WordBreakProblem.class

Is there a correlation between two issues here?

Upvotes: 2

Views: 10330

Answers (3)

Josh A
Josh A

Reputation: 51

Have you re-saved the code? In eclipse you need to save the changes made otherwise it will run what is previously saved. Or potentially try rebuilding the path if it is not saved to the right area.

Upvotes: 1

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

Eclipse by default recompiles the projects after saving a change. This is noticed by Project > Build Automatically. If this option is unchecked, eclipse won't recompile the workspace after saving a small change. IMO this is option is useless when you have too many projects/files and recompilation can take several minutes.

If you have disabled this option (like me), then check this other option in Window > Preferences > Run/Debug > Launching > Build (if required) before launching:

Build before launching

If this option is disabled, then no matter how many times you change the classes or resources in the project, you will have to manually fire a build for the project(s) before launching it.

Upvotes: 3

Brian
Brian

Reputation: 13573

  1. Have Build Automatically checked

enter image description here

2. The correct way to run WordBreakProblem class is

java WordBreakProblem

instead of

java WordBreakProblem.class

Also make sure you compile the java source code into WordBreakProblem.class by using

javac WordBreakProblem.java

before doing step 2.

3. If the code still doesn't refresh, try "clean".

enter image description here

Upvotes: 7

Related Questions