Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 425017

Summary: After ANT task compiles - Eclipse project shows lots of errors when running App
Product: [Eclipse Project] JDT Reporter: MH <mhilpert>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: major    
Priority: P3 CC: jarthana, sptaszkiewicz, srikanth_sankaran, stephan.herrmann
Version: 4.3.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug

Description MH CLA 2014-01-07 09:47:24 EST
This problem exists since many Eclipse versions: when compiling classes with an ANT task and right after the task finished, the corresponding Eclipse Project is startet (Java Application), the whole Project gets red error buttons and the requester pops up "Errors in Project exist ...".

The workaround is to clean the project (Project > Clean) and then start the Run Configuration again.

Each Java Project has a custom ANT build file and we use the Eclipse ANT view to include those ANT files. These files have targets like "create debug JAR", "create production JAR", etc. So we always build our JARs with these custom ANT files.

If we wait long enough (e.g. 5 seconds after the ANT task was finished), the Java Applications runs flawlessly in Eclipse. But as you can imagine, the developer wastes enough time to wait for compilation and as soon as the JAR is finished, he wants to start the application. This leads to dozens or hundreds of project cleanups ... for each developer ... each day.

It seems that Eclipse has problems with ANT tasks that also touch the Java source and class files. Look like a synchronisation problem. If the ANT tasks returns, everything should be finished - so I wonder why Eclipse needs extra time to start such Java applications without compilation errors.

BTW: we deactivated "build automatically"!
Comment 1 Stephan Herrmann CLA 2014-01-07 17:42:58 EST
When you launch ant, have you selected anything on the "Refresh" tab?

Another option to (un?)check: 
  Run/Debug > Launching > [x] Build (if required) before launching.

I assume that your launches perform a build on only partly refreshed resources, hence the garbage.


On a different note, I'd expect you'd get better results by letting Eclipse do the compilation and using ant only for packaging into jars, this might significantly reduce the time you have to wait for building - and provides for a clean separation of responsibilities.
Comment 2 MH CLA 2014-01-08 04:11:32 EST
Nope, the Refresh tabs don't have "Refresh resources upon completion" checked.

Where is "Run/Debug > Launching > "?

We don't use Eclipse for compilation before makeing JARs because we have misc ANT tasks to compile with different compiler parameters.
Comment 3 MH CLA 2014-06-04 04:35:50 EDT
This still occurs with eclipse-java-kepler-SR2-win32-x86_64.zip. The project is clean - when I Eclipse-Clean the project: no errors. Then I call my custom ANT target (out of Eclipse's ANT view) to create a JAR file from my project. In about 30% of those cases, the Eclipse Java project suddenly shows compiler errors. When I just clean the Eclipse project, the errors vanish.

This error occurs several dozen times a day which makes development very frustrating (as we constantly deploy JARs on the development server). When I wait a minute between Eclispe compilation/clean and starting my ANT target, the error never occurs.

So, this is a threading issue with Eclipses internal cleans/refreshes/whatever and the custom ANT target that also compiles the source files and creates a JAR.

Even though I have "Build Automatically" switched OFF, Eclipse seems to somehow compile/check/whatever the class filesright when my ANT target compiles the same source files (of course to the same output class folder).
Comment 4 Stephan Herrmann CLA 2014-06-05 17:47:25 EDT
(In reply to MH from comment #2)
> Nope, the Refresh tabs don't have "Refresh resources upon completion"
> checked.

My question was meant as a hint: try *enabling* this option to see if this gets your workspace in sync with the filesystem and thus avoids the garbage.

> Where is "Run/Debug > Launching > "?

In the preferences
Comment 5 MH CLA 2014-06-10 03:22:24 EDT
I already have "Build (if required) before launching" enbaled => bug still occurs.
Comment 6 Stephan Herrmann CLA 2014-06-10 09:06:27 EDT
(In reply to MH from comment #5)
> I already have "Build (if required) before launching" enbaled => bug still
> occurs.

This option is more likely to *contribute* to the problem than fixing it. *Unchecking* could perhaps help.

However, the main hint I gave regards "refresh" not "build". Have you tried that??
Comment 7 MH CLA 2014-06-10 14:28:15 EDT
Okay, I now checked all boxes on the ANT refresh tab. Today, the error didn't occur anymore. Hope, this was the reason!

But I don't understand that I have to check the refreshing ... without refreshing, Eclipse should do nothing. But it does mark most files with thousands of errors. So, this means that Eclipse is doing SOMETHING ...
Comment 8 Srikanth Sankaran CLA 2014-09-10 23:09:30 EDT
This looks by design, Passing to Platform for confirmation.
Comment 9 Szymon Ptaszkiewicz CLA 2014-09-15 05:54:02 EDT
It seems that the Ant task modified some workspace content and then a refresh is needed to put it back in-sync. I can't tell why errors are shown without refresh but it means the Java builder was run and found some (potentially dubious) errors. I guess it depends what are these errors about. There is nothing more we can do without a reproducible test case.
Comment 10 Jay Arthanareeswaran CLA 2014-09-15 23:54:39 EDT
(In reply to MH from comment #3)
> This still occurs with eclipse-java-kepler-SR2-win32-x86_64.zip. The project
> is clean - when I Eclipse-Clean the project: no errors. Then I call my
> custom ANT target (out of Eclipse's ANT view) to create a JAR file from my
> project. In about 30% of those cases, the Eclipse Java project suddenly
> shows compiler errors. When I just clean the Eclipse project, the errors
> vanish.

Does the JAR created related to the project or it's classpath in any way? Where do the classes compiled by the ANT task go? Can you try making it use a location outside the folder for output, just in case?
Comment 11 MH CLA 2014-09-16 02:56:52 EDT
The projects don't create the JARs only the class files. The ANT task for each project compiles the same source files from the eclipse project, creates the same class files as the Eclipse project and creates the JAR (that is not related in the Eclipse project). 

So, the critical part seems to be the class files. The ANT task basically does:

1. delete class files
2. compile sources to recreate the class files
3. create JAR from these class files

SOmehow, Eclipse is doing things in the background and perhaps, when the class files are deleted get somehow "out of sync" and goes crazy. But once the project is marked with hundreds of errors, it never turns back again clean - even when the ANT tasks is finished and the class files are recreated. I have to do a "clean project" manually.
Comment 12 Jay Arthanareeswaran CLA 2014-09-18 02:32:22 EDT
(In reply to MH from comment #0)
> BTW: we deactivated "build automatically"!

Are things any different/better when it's turned on?
Comment 13 MH CLA 2014-09-18 17:36:17 EDT
Nope, it gets worse. I guess it's simple: Eclipse does not sync with the ANT view and its running tasks.
Comment 14 Jay Arthanareeswaran CLA 2014-11-09 23:55:52 EST
(In reply to MH from comment #13)
> Nope, it gets worse. I guess it's simple: Eclipse does not sync with the ANT
> view and its running tasks.

I don't know what might be going on. I also can't promise much time for this as of now. Meanwhile, may I suggest a workaround of having ANT create the .class files in a location outside project's classpath if the goal is only to create the JARs? I think that should work.
Comment 15 Eclipse Genie CLA 2020-04-15 02:50:57 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.