5

I have a project in Eclipse (Indigo but similar in Helios) which has files in src/main/resources which get processed to generate *.java source files in target/generated-sources/xyz. The project settings have "Build Automatically" enabled so whenever these resource files are edited and saved the corresponding *.java files are generated. I've added target/generated-sources/xyz to the projects Build Paths. This all works perfectly.

The problem is that the changes to the generated *.java files are inconsistently rebuilt. If I have one of those files open in the editor, then it notices that it changed and asks if I want to reload it. Reloading the *.java files is enough for it to recognize that it has changed and trigger a rebuild. If I don't have it open then it doesn't automatically pick up the changes.

Any ideas on what I can do to let Eclipse (Indigo preferably) know that these generated files are being updated? Or better yet tell it to monitor those folders directly?

Thanks.

mckamey
  • 17,359
  • 16
  • 83
  • 116

3 Answers3

13

Try configuring Eclipse to automatically refresh. I'm not sure about Indigo, but in Helios, it's in Preferences → General → Workspace → Refresh Automatically.


Here it is in Indigo:

screenshot

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • There you go! That seems to have done it. In Indigo there are two options now: "Refresh using native hooks or polling" and :Refresh on access". Playing with which is better but it appears that once it refreshes it picks it up and rebuilds. Thanks! – mckamey Jun 30 '11 at 22:08
  • You're welcome. I just remembered I have a dormant copy of Indigo. I'm not sure which of the new options is better. No idea why Eclipse doesn't automatically refresh by default. – Matt Ball Jun 30 '11 at 22:10
  • 1
    Perhaps because someone could lose changes I guess. I am often outside the IDE so I like having it stay in sync. For me (on OS X) "Refresh on access" seems to work instantaneously. The other seems to be on a short but noticeable polling cycle. **Edit:** scratch that. Just setting both. :) – mckamey Jun 30 '11 at 22:13
  • I am using eclise 2020-03 and there I don't see build automatically option as shown in above screenshot – Rahul Jain May 19 '20 at 07:19
2

I assume you have added an "Program"-based builder to the project that compiles/translates the files into .java.

If you open the builder - via project properties -> Builders -> Edit... builder - then you can open the Refresh tab - se below.

Refresh tab of the Builder Dialog

Here you can then select which resources to refresh when this particular build is run... E.g. all resources in target/generated-sources/xyz...

Tonny Madsen
  • 12,628
  • 4
  • 31
  • 70
  • Thanks, that's a good tip. In my case, it is actually a maven based process that is configured with m2e. I wish that these types of actions could be specified cleanly in the `pom.xml` so that each dev didn't have to setup the IDE. – mckamey Jul 01 '11 at 16:14
0

with "build automatically" option checked, it is not building on clean. What I had to do extra is, clear all error logs and Problems, then the correct setup can produce class files.

Feng Zhang
  • 1,698
  • 1
  • 17
  • 20