Project refresh and clean in eclipse [duplicate] - eclipse

What's the difference between
"Eclipse/Project/Clean..."
and
"Eclipse/Project/Refresh (F5)"
I often have to "rebuild" my workspace that contains few inter-dependent projects, and I am unsure which is the best way to make a clean start?

As mentioned here
Refresh analyses the source-files to check if any changes were made from outside Eclipse, and if so, compiles files that were changed.
Clean on the other hand removes all compiled classes and forces recompilation of the whole project (or workspace).

Clean deleted the generated resources like compiled classes and makes sure that latest code base is recompiled again where as
Refresh syncs the eclipse project from the actual folder structure which makes sure that any changes done to files and/or folder structure is available to eclipse...

Clean will clean all the compiled files from the selected projects. It will trigger a rebuild if Build Automatically (in the project menu) is enabled.
Refresh will reload the files in the project from the filesystem.
For your question, Clean will be the answer. Make sure that you have Build Automatically checked.

Related

Should the .gradle folder be added to version control?

Gradle creates a folder called .gradle. Should I track it with my version control (i.e. git)?
More importantly, why / why not?
Should I track the .gradle directory?
No. It can safely be ignored.
Why should I ignore it?
It's purely for caching information, you don't want it in your repo because:
it can get big and be full of binary files
there can be machine specific data in there
there's a lot of churn in there (you'd be constantly committing changes to files in there)
everything in there can be completely re-generated whenever it is needed anyway
It's basically a temp directory that Gradle is dropping in the middle of your source code (why Gradle thinks that's an appropriate thing to do is a different question).
You can tell the "cache directory" nature of the directory by the name of the switch that lets you change where it goes: "--project-cache-dir".
Though I hate having binary files in my source tree, I usually just end up adding the directory to my ignore file because somewhere along the line I'll forget to use the switch from some command line or from my IDE or something and then end up having to deal with the directory anyway.
How do I ignore it?
Git users can add a line with just .gradle to the .gitgnore file and Git will ignore all files in any directory with that name.
Mercurial users will want to look up the .hgignore file.
For other version control systems, refer to the documentation - they all have a feature to support this.
The .gradle folder contains different calculated information about your gradle build (e.g. cached outputs/input information). You definitely shouldn't check that folder into your version control system.
I was new to Gradle and thought that the .gradle folder will contain generic information such as dependency mappings, etc and uploaded it on version control. I then tried setting up a new machine with a different OS flavor and Java version using code from the version control including the .gradle folder and ran into errors. Turned out that the .gradle folder contains machine specific information and is used for caching on local.
Do not include the .gradle folder in version control and try setting up a new machine with the code, the gradle daemon will do the rest.
You don't need to keep the .gradle folder.
Because once you execute gradle build command again, you can make almost the same .gradle folder again.
But when you use the gradle.setting file under .gradle you might need to move it to root folder of the project.
when we start the gradle it create the .gradle folder inside your home directory. It consist of native (information about your system) and caches. Caches further consist of plugins and all other jars dependencies.
When we build the the project first time at that time it download dependencies and plugins and cheched them here. next time when we need them it, it get from here. even when we need them in eclipse to compile the code (=>gradle eclipse), its dependencies are added from cache
As it will keep updating and adding when you run gradle. so i guess we do not added it to version control.

Eclipse: The project was not built since the source file ... could not be read

When compiling my Java project, I get this error in Other errors:
Description Resource Path Location Type
The project was not built since the source file /PROJECT/src/main/org/../ABC.java could not be read PROJECT Unknown Java Problem
Indeed, the file is listed in Package Explorer but shows only "Error retrieving content description. On the file system, the silent dir exists but not the file; git status is missing nothing. How do I resolve that compile error?
Simply restart eclipse, refresh all projects and do a clean build. That should fix it. Don't forget the eclipse restart, else no matter how many times you do a clean build or refresh, it will not fix the problem
Looks like someone has deleted that file but eclipse still think that file is part of the project. Might have happened when someone deleted a file from the source control in an improper way.
If you dont have pending changes then you can get fresh copy of the project and import it into your workspace.
If you have pending changes then take a copy of changes and repeat above step. ( A restart of eclipse may be necessary)
It can be related to missing location
Select File => properties => Resource => Edit file location.
I know the answer is accepted but in my case that solution didn't work for me, I had restored files from a backup to my local project in linux and the files I restored were owned by root with only the owner being able to read/write the files. SO, I sudo chowned the files "sudo chown _R myUser:myUser *" at the base of my project, refreshed in Eclipse (f5) and the annoying repeated failure of my build was a thing of the past.
If you are writing Maven projects, try right click on the project and select [Maven] -> [Update Project...]
It works for me.
For me there was a different solution than mentioned here.
I was doing a no-no, I imported a project that had a .project file, and there was some errors in the way my version of eclipse was reading some of the files. The package names and files had a little ! symbol with a yellow background.
The solution was to delete the packages. Obviously make a backup. But in doing this most times the files nor the packages were deleted. Instead eclipse refreshed and the desired files were there. Sometimes I had to hit refresh (F5), and sometimes I had to restore files.
I found it best to delete the packages as that is where eclipse was having reading the data.
If the missing file is still mentioned in the Linked Resources, no refresh and restart of Eclipse will ever solve the problem. You have to delete the file in the Project Properties Linked Resources list.
For anyone using VS Code with the RedHat Java plugins (which use Eclipse tooling under the hood), I got this error as well. I fixed with the following:
# Quit VS Code
rm -rf ~/Library/Application\ Support/Code/User/workspaceStorage/*
# Reopen VS Code
As all others said, it is most probably an issue with the internal caches of Eclipse.
I usually restart the IDE with the additional -clean option to wipe out the OSGi-related caches, then clean and rebuild all the projects.
If the problem persists, I realized that cleaning up the single affecting project works better that cleaning up the whole workspace. (Ominous... XD)
This usually happens to me when merging changes that imply renaming or deletion of source files, prior to launching Eclipse.

Does refreshing in Eclipse also Clean the project?

I hope the question isn't too vague but I was wondering if running 'Refresh' also calls 'Clean'.
Does running 'Clean' run 'Refresh' ?
Nope, it does not. Refresh reloads the last version of your project's files (like, if you modified something outside of eclipse, you need to refresh in eclipse to have the new modif show up). Clean on the other hand deletes all the compiled files and recompiles your project's sources
No, it doesn't. Eclipse reads the files from the file system and buffers them. Refresh only tells eclipse to reread the files.

Query, while creating a jar?

Resource is out of sync with the file system
This the error that is thrown out while creating a jar in eclipse IDE...
What does this mean? And how to rectify it?...
I'm assuming this is while you're using Eclipse...
I suspect that it means you've changed a file on the file system but the Eclipse workspace is still "looking at" the old version. Hitting Refresh (F5) on either the file or the whole project would usually sort it out. If you're seeing it every time you create a jar file, that suggests your project is looking at your build output, which isn't ideal.
Eclipse caches file content to make things go faster.
It has detected that the version on disk has changed since it was put in the cache, and you need to refresh the workspace to update the cached version.
This typically happen when you fiddle with files outside of Eclipse. If the process doing the fiddling is invoked from within Eclipse you can tell Eclipse to refresh the workspace when the process is finished.
Eclipse keeps metadata about all files within every eclipse project. "Resource is out of sync with the file system..." means that eclipse has noticed that a file has been changed (or deleted) from outside eclipse. Refreshing the project in question (from the context menu in the package explorer) should fix the problem.

Why is eclipse trying to compile files not in my build path?

I have a rather large project which contains a number of third-party dependencies which are linked via svn:externals. These include tomcat and blazeDS, which are packaged by our installer via ant. The problem is that these projects contain dozens of sample JSP pages, and eclipse chokes on them when trying to build the project, producing hundreds of errors.
Our project setup is something like this:
src/
main/
test/
third-party/
blazeDS/
tomcat/
etc.
Now, in eclipse, my project's build path is set to only include subfolders in src/main and src/test. Yet, for some reason, it still tries to build everything beneath third-party. I have clicked on third-party and selected "remove from build path", but this had no effect. I even tried adding the third-party folder to the build path, and then excluding "", "/*", and "**/*.jsp", but again, to no effect.
What is going on here?
Edit: Thanks for the suggestions, though unfortunately, they don't seem to fix the issue. I don't have the CheckStyle plugin installed (I'm using Eclipse 3.4.1 with the only custom plugins being subclipse and flex builder), and I tried disabling all extra builders except for Java, but the errors are still being thrown.
I usually have this kind of issue with CheckStyle plugin, where you need to specify in its properties (right-click on project -> Properties -> CheckStyle):
"Exclude from check Files non located in a source directory"
Otherwise it does analyze (and reports warning/errors on) files which are not candidate to be compiled in the first place.
Couple of other suggestions:
try restarting your eclipse with the -clean option (eclipse software version of 'did you reboot it ?' ;) ). Beware it can reset your workspace perspectives, so you may want to try that with a copy of your workspace instead.
try deleting your project (your workspace reference of your project, not its actual content), and reimporting it (beware of your custom launchers, they may get removed in the process).
check if you do not have any linked directory within src or test, which would point to thirdparty(/**): that would explain the unwanted compilation.
It could be that your eclipse project is configured to have extra Builders. You can check that in the project's properties (right-click on project -> Properties -> Builders).
In my case it was because there was a reference to the file (which I had excluded from the build path) in another file which was in the build path. I wanted to exclude SegModel.hpp from the build path, but in another file, I had specified template short K::KEstimate<SegModel>(SegModel& m, short stepCode);