Monday, March 2, 2009

NetBeans and Workspaces


If you're familiar with both Netbeans and Eclipse, you'll probably know of one obvious difference which sets the two apart: Eclipse supports "workspaces", while Netbeans does not (or at least, doesn't appear to--read on). A workspace is sort of like the "state" of the IDE--it's a collection of open project folders and IDE settings. Workspaces are useful when you are working on two unrelated projects which use different code and require the IDE to be configured differently.

By default, Netbeans only allows you to have one workspace. That is, when you exit Netbeans, all your open projects and settings will be restored when it is launched again. This is different from Eclipse, which asks you to specify a workspace every time it is launched. There is a way to specify your workspace with Netbeans as well, though it's not through an easy-to-use UI. An extra parameter must be included when invoking the Netbeans executable:

--userdir C:\path\to\workspace

Here is how to do use this parameter in Windows:
  1. Create a shortcut on your desktop to the Netbeans executable: C:\Program Files\NetBeans x.x\bin\netbeans.exe.

  2. Right-click on the shortcut and click "Properties".

  3. In the "Target" textbox, add the extra parameter to the very end:

    --userdir C:\path\to\new_workspace

  4. Click "OK" to exit the Properties window and double click the shortcut. Netbeans will launch and create/load the workspace at that location.

Tip: I like to use my default workspace as a "jumping-off point" for all my new workspaces. This saves me time I would otherwise have to spend resetting all my IDE settings, like SVN and code formatting preferences. Just make a copy of the default workspace folder and create a shortcut pointing to that folder, as shown above. The default workspace is located here:

~/.netbeans/<version>

2 comments:

Michal said...

Perfect tip!!! Thank you!

I was searching for it for a while! It took some time before I came with a word "workspace". First I tried "netbeans how to save opened tabs" or "netbeans how to save opened windows".

Maybe now there is a way to easily switch/load the workspaces? Or maybe this is possible to write a macro or something to easily switch between opened files?

I often work on the same project but different tasks which demand different files opened.

mangst said...

Michal,

Thanks! I haven't used Netbeans in a while, so I don't know if they've added anything to make this easier or not.