6

Note: I don't find this being a duplicate of any question. I have done a lot of research on this (few hours, read whole Google about workspaces probably - it's a metaphor of course) but couldn't find the answer to my problem.


So I have done some programming in Java and mainly used Eclipse for it (when projects were getting more complex, before I had used Vi). I was always working in that default workspace $HOME/eclipse-workspace because I never really understood the point of workspaces.

I am back to programming in Java, installed Eclipse and get prompted to Select a directory as workspace which kindly offered me to use /home/campovski/eclipse-workspace. Before I would just hit Launch but now I started getting curious. What are these workspaces, what are they used for...?

I have done some research:

I also followed the links that were provided in answers to the first link but none gave me the answer to my question:

What is the difference between a directory and a workspace?

As is stated in third link: A workspace can have any number of projects, each of which can be stored in a different location in some file system. Ok, this might be useful, but what is the problem of including all projects in one parent directory which could serve instead of a workspace?

If we take Matlab for example: enter image description here

There you have a directory selection menu on the left, just like in Eclipse. The current directory you are in is selected as a working directory and any Matlab function and scripts declared in this directory can be executed in the Command Window. The analogy from Eclipse would be as to import a function from different folder.

So my question to rephrase it is, is there anything else to workspaces than workspace just being a collection of projects, folders and files, just like a normal directory, except that in workspace there can be projects from different paths.

campovski
  • 2,979
  • 19
  • 38
  • 2
    Yes, there is something more. There are some (hidden) files and directories created by eclipse containing configuration information. Of course else it is a directory in respect to your OS. – Uwe Allner Sep 07 '17 at 08:27
  • Might be handy for project management too. For example an application can be build out of multiple Java projects and you have the work space as a collection of projects for the application. But yeah it's still a directory in the end. – Mark Baijens Sep 07 '17 at 08:31
  • @MarkBaijens I understand that. But still, I could have this directory structure: Projects with subdirectories Project1, Project2, Project3 and when I would want to make a finished application, I would click on something like *Export to application* and would be prompted with a window to select what projects I want to include. Seems easier to me than creating workspace over workspace and then needing to switch from one another when I would want to work on different applications. – campovski Sep 07 '17 at 08:34
  • @UweAllner When prompted to select workspace, this is what is written: *Eclipse uses the workspace directory to store its preferences and development artifacts.* So I know that. – campovski Sep 07 '17 at 08:36
  • Of course you do not need to create a new workspace for every project. Which project you want to have in which workspace is your decision. You can put all your projects into one large workspace if you want, or you can group them by any system you want. But implicitly you will have at least one workspace, which is created by eclipse. – Uwe Allner Sep 07 '17 at 08:49
  • @UweAllner As described in an answer below and by your comment I conclude that I create new workspace in case I need to change some preferences, e.g. visuals. I also assume, haven't checked yet, that I can also set different different Java versions to be used in each workspace. – campovski Sep 07 '17 at 09:38
  • 2
    @campovski The default Java compiler settings like the Java version are set in the workspace, but can be overridden by project specific settings (which are stored in `.settings/org.eclipse.jdt.core.prefs` of the project). Project specific settings are for sharing via version control (compiler settings, formatter profile, etc.), while workspaces preferences are for yourself (color theme, font sizes, etc.). – howlger Sep 07 '17 at 10:09

3 Answers3

7

Workspace it's like user's homedir in linux.

Workspaces bind together JRE version, installed servers, and if you're using server connectors, all the data and temporary WARs, EARs are saved there (.metadata/plugins). Switching workspace is for switching context of your work: project, client, language, paradigm ... Workspace is the directory from where ECLIPSE bootstraps itself up. All local dependency resolutions ends up in workspace directory.

VisualStudio's "solution" concept is not even near to the concept of workspace, as solution is just parent folder to group one or more projects and give them some common CLR names and properties.

I'm using Eclipse for at least 10 years now... I got to this conclusion : I have same workspace for all projects that use same JRE and same APP server. I have different Eclipse versions, if I need some special tooling (Spring or CDI or PHP or some exotic plugin). All workspaces are located in my home directory.

You can paste / copy workspace to different computer, with same Eclipse version it works out of the box.

Mitja Gustin
  • 1,723
  • 13
  • 17
6

Simplified, a workspace is a special directory that is monitored by Eclipse: a change inside the workspace directory can trigger something.

For example, a Java file that will be saved will be compiled and might create error markers in a dependent Java projects. Changes made outside of Eclipse are visible inside Eclipse only after a refresh (assuming Window > Preferences: General > Workspace: Refresh using native hooks or pooling is disabled): instead of slow file accesses, Eclipse stores states of workspace files internally.

From a historical point of view, the workspace concept can be seen as a compromise between database and file system (in IBM VisualAge which can be seen as the predecessor of Eclipse the Java source code to be edited was stored in a database).

In addition:

  • Multiple instances of Eclipse can run concurrently, each with its own workspace.

  • Eclipse stores almost all preferences (Window > Preferences) in the workspace (in the .metadata subfolder). Different workspaces can have different preferences.

  • The .metadata subfolder is also be used for caching to speed-up Eclipse.

I suspect that the target platform that is required to develop Eclipse with Eclipse (dogfooding) also played a role in the decision for the workspace concept (see also Eclipse bug 392652).

howlger
  • 31,050
  • 11
  • 59
  • 99
  • Ok, I find the second bullet really useful. Thanks! – campovski Sep 07 '17 at 09:34
  • I suspect that the target platform that is required to develop Eclipse with Eclipse (*dogfooding*) also played a role in the decision for the workspace concept. – howlger Sep 07 '17 at 09:45
1

Think of a Java interface and a concrete class implementing that interface. It's similar for the Eclipse workspace and the underlying directory.

A workspace as a logical container for projects and configuration. That logical concept is implemented by a physical directory on your file system. The way it's designed, it would actually be possible (in theory) to implement a workspace using something other than a (local) file system (similar to what VisualAge for Java did, as referenced in @howlger's answer), although I don't know of any such implementation.

The point is, what you interact with while using Eclipse the IDE is a concept; it's best to not think about it too much as a filesystem directory. Doing so leads to some assumptions that won't always hold true, if you get deep enough into using it. Going back to the first sentence of this answer, you can sometimes get away with assuming a particular implementation of an interface, but doing so has hazards if you're not careful.

E-Riz
  • 31,431
  • 9
  • 97
  • 134