How to dynamically modify workbench.xmi during startup runtime-eclipse - eclipse

Since user did some complex operation happened in my Eclipse Rcp Application, which causes some wrong setting happened in user's workspace, (with some projects existing in the workspace).
And when user start to run on the application in that "bad" workspace, the Eclipse RCP gui looks weird, and the existed projects can't opened properly.
After research, I found it's because of some wrong settings happened in workbench.xmi file located in .metadata/.plugins/org.eclipse.e4.workbench, in the user's workspace.
A workaround is to manually change remove the wrong settings in workbench.xmi, or change to a new workspace and copy user's projects into the new workspace.
My question is how to dynamically identify the wrong setting workbench.xmi file located in user's workspace, so that I can change the content of workbench.xmi, during startup my Eclispe RCP application ? So that user don't need to do the manual workaround.

Related

Where does Eclipse store the info about which workspace to start up with?

When I launch Eclipse it starts with one of the workspaces I created and selected "don't ask again" (standardly, Eclipse asks about which workspace to start with during the startup).
So it must store somewhere which workspace to use. Where does it store this piece of information?
In
$HOME/.eclipse/org.eclipse.platform_3.7.0_155965261/configuration/.settings
there is a file
org.eclipse.ui.ide.prefs
where it is stored.
With Eclipse Juno, I can see this information in:
eclipse\configuration\.settings file.
I guess you are looking for RECENT_WORKSPACES and SHOW_WORKSPACE_SELECTION_DIALOG vars.
The settings have changed since this question was posted, as newer versions of Eclipse have been released.
With Eclipse Luna, navigate to $ECLIPSE_HOME/eclipse/configuration/.settings and the file org.eclipse.ui.ide.prefs contains settings like this (Windows file configuration shown):
MAX_RECENT_WORKSPACES=5
RECENT_WORKSPACES=C\:\\src\\eclipse-workspaces\\luna\\MyApp\nC\:\\src\\eclipse-workspaces\\luna\\MyOtherApp
RECENT_WORKSPACES_PROTOCOL=3
SHOW_WORKSPACE_SELECTION_DIALOG=true
eclipse.preferences.version=1
Each entry in RECENT_WORKSPACES appears to be delimited by \n with no spaces. Whenever I manually shuffle my workspaces around (which is rare, but it happens), I've had great success hand-editing this file, saving it, and having the new paths show up just fine in the Workspace Lancher/Select a Workspace dialog.
You have eclipse configuration files in "eclipse_home"/configuration and the one you may looking for is in settings directory : org.eclipse.ui.ide.prefs
I was facing an issue with Spring Tool Suite 4. The workspace used to give an error and I wasn't able to select other workspace also. With the help of some answers already given, I could locate the configuration in $ECLIPSE_HOME\sts-4.7.1.RELEASE\configuration.settings\org.eclipse.epp.mpc.ui.prefs
I removed RECENT_WORKSPACES property (after you try to restart, it adds default entry again) and changed
SHOW_WORKSPACE_SELECTION_DIALOG=true
STS started showing workspace selection dialog again.
If Eclipse has been installed with ubuntu-make, the file location is ~/.local/share/umake/ide/eclipse-jee/configuration/.settings/org.eclipse.ui.ide.prefs.

Where does eclipse store information about open perspectives etc?

After a recent upgrade to eclipse Juno, I have a problem with eclipse no longer being able to remember certain settings across restarts and workspace switches. Things like which perspectives were open, certain settings like "[x] Open Dashboard" (spring ide) seem to revert to their factory settings whenever eclipse is restarted.
I use Ubuntu and for historical reasons I maintain my eclipse installation in /opt/eclipse. The installation is owned by root, and apart from some issues with upgrades, this has not actually been a problem - until the Juno release.
I have tried chown -R myself:myself on the eclipse installation directory, and I have verified that all files are indeed editable by my own user. Still, the perspectives seem to reset.
Is there any other place where eclipse stores this information, which might still be owned by root?
Information about perspectives is stored in < workspace>\.metadata\.plugins\org.eclipse.e4.workbench\workbench.xmi
Keep this file backed up if you use complicated customized perspectives.
P.S. It's also useful to know that deleting this file may solve the problem when Eclipse doesn't start (see also here)
That information is kept in the .metadata directory in each workspace root directory.
Two solutions:
MENU -> File -> Switch workspace -> Other -> Copy Settings of
Workbench Layout
Working Sets
Copy/backup and replace following folder to new created Workspace.
[workspace]/.metadata/.plugins/org.eclipse.ui.workbench/
[workspace]/.metadata/.plugins/org.eclipse.core.runtime/.settings/
Personally I prefer (2).
The above answer is credited to #Ischin, in the following reference...

How do workspaces work in Aptana 3?

I'm new to programming and IDEs. I never understood the concept of a workspace in Eclipse, and I don't understand it in Aptana.
With Eclipse I just put it into my web root. Not sure if that's the way to go?
Can someone explain what a workspace is and where it should go? And if not in the web root, then how do I launch a PHP page from within the EDI?
Thanks!
An Eclipse workspace is a directory where (generally) all of the files you are working on live and that stores all of the state (like preferences and such) for a single user of Eclipse. So when you create projects, they are located in the workspace. The workspace has some metadata files that control how Eclipses behaves for you.
Eclipse keeps a representation of the workspace internally, which means the workspace can get out of sync with the underlying files. To sync them up, do a right-click Refresh in the Package/Project Explorer.
Usually the workspace goes into some directory relative to your home directory, since it's private to each developer.
Workspaces are like folders where the project's files are.
When you have a local web server you could set the workspace to a new folder in the servers directory (or web root when the project should be in the main directory!) . If you want to add a new PHP-file in Aptana studio 3 just right click the workspace and select add new file (or sth. like that). After that you will be able to enter a file-name and it's gonna be saved in the workspace (folder). But of course you can also work without workspaces, just create the the PHP-File and edit it with Aptana.

eclipse: explicitly saving project / workspace

Is there a way to force Eclipse to save project / workspace settings? I can't find a "save workspace" or "save project" command.
(I've never had a problem with this in Eclipse, but TI's Code Composer 4 is based on Eclipse and it sometimes crashes and doesn't retain the changes I made in project settings.)
The surest way to force such a save would be to switch workspace.
Switch to an empty workspace, and then switch back to your current workspace: every project settings should have been saved and restored.
Note: the bug 27821 ([Workbench] saving state and preferences) is a duplicate of:
bug 2369 ([Workbench] Would like to be able to save workspace without exiting), which is opened since... 2001!
So even the "switching workspace" trick might not be enough to save every settings, but that is a start.
Edit September 2011:
Aaron Digulla add in the comments he has added a plugin 'saveui' (bug 337593, which duplicates bug 2369), and which could be a good solution to save your workspace state (without having to close your Eclipse or switch your workspace).
To use this plugin, download the code, open the archive, copy the "dropins" folder into your "eclipse" folder (possibly merging with the existing dropins folder), close Eclipse, and re-open Eclipse. You should see a small lock-like icon in the toolbar, just below the menus. Clicking this icon is supposed to save the workspace.
The place where is a workspace - workbranch is in
Workspace\.metadata\.plugins\org.eclipse.e4.workbench\
You can use wakeup() method to force save workspace
Job[] jobs = WorkbenchJob.getJobManager().find("WorkbenchAuto-Save Job");
Job workspaceJob = Arrays.asList(jobs).get(0);
workspaceJob.wakeUp();

"Workspace is closed" exception when trying to get the workspace through ResourcesPlugin

I get this error when trying to get the workspace through ResourcesPlugin:
java.lang.IllegalStateException: Workspace is closed.
at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:339)
The code generating this is:
IWorkspace ws = ResourcesPlugin.getWorkspace();
Can you please help with this problem?
Does your Manifest.MF contain the org.eclipse.core.resources in the Require-bundle section ?
And do you launch your test as a plugin ? (not as a 'Java Application')
See also this thread.
As mentioned in the "Resources and the file system" help page,
You can access the workspace from the resources plug-in class (defined in org.eclipse.core.resources).
When the resources plug-in is not running, the workspace exists solely in the file system and is viewed or manipulated by the user via standard file-based tools. Let's look at what a workspace looks like on disk as we explain the resources plug-in API.
From this book:
The workspace directory, regardless of the name defined with the -data invocation option, has two roles:
it acts as the parent for the .metadata directory
and as the default location for projects
the workspace can contains projects only when:
the org.eclipse.core.resources plugin is included in the configuration and
and appropriately started from the workbench
this is automatic from an IDE configuration based on the org.eclipse.ui.ide.workbench application.
See also this thread and remember that:
the workspace is a different workspace from the runtime-workspace that's used for testing plugins. When you do Run on an Eclipse PDE environment, it creates a new workspace which is completely empty.
The testing workspace root can be specified through the "-data" launching option.
If you want to access a file, your best bet is to include it in the plugin itself, and then use getClass().getResourceAsStream("/myfile.txt") to get an InputStream that you can read the contents for.
Try calling Plugin.getStateLocation() in the plugin, it should cause the workspace to be created for you. Without this, you can't save any preferences either. http://dev.eclipse.org/newslists/news.eclipse.platform/msg45020.html
http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/core/runtime/Plugin.html#getStateLocation%28%29
Err, sorry -- I just completed necroed this question by accident :)