Thursday, February 19, 2009

Open with NetBeans context menu in Windows

This post covers the following topics:
  • How to add Open with NetBeans to windows file and folder context menu
  • How to open any file in NetBeans without creating a project
  • How to use NetBeans IDE as a file and folder explorer
  • How to use the --open command line option for NetBeans IDE

--open command line option for NetBeans IDE
NetBeans IDE identified --open command line option and opens the file or folder given as an argument after this command line option.  This fact makes the NetBeans IDE useful to open any file and folder through command line.  In windows we can use this feature to introduce a context menu for files and folders in Explorer by tweaking the Windows Registry.

Adding Open with NetBeans option to windows context menu
In windows we can add two extries to the Windows Registry to add Open with NetBeans option to the Windows Explorer context menu.  These entries need absolute path of the NetBeans IDE executable so while trying this trick please check the NetBeans IDE executable path.

My NetBeans IDE 6.5 executable path is

C:\Program Files\NetBeans 6.5\bin\netbeans.exe

We can add the registry entries manually by opening the regedit.exe application from the Start > Run menu, or we can create a REG file to achieve this.  Creating the REG file is the easiest option.  We will create a file with name openwithnetbeans.reg and we will copy the following contents in that file. Double clicking this REG file will add these registry entries to the Windows registry as required.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Open with NetBeans\command]
@="\"C:\\Program Files\\NetBeans 6.5\\bin\\netbeans.exe\" --open \"%1\""

[HKEY_CLASSES_ROOT\Folder\shell\Open with NetBeans\command]
@="\"C:\\Program Files\\NetBeans 6.5\\bin\\netbeans.exe\" --open \"%1\""

Now when we open the Explorer and right click on a NetBeans project folder we get option as Open with NetBeans and clicking on this option will start the NetBeans IDE and will open this project in the IDE.

We can see the project open in the NetBeans IDE for us.

When NetBeans IDE is already open this command will open the project in the existing IDE.  

Opening any file in NetBeans IDE from Windows Explorer
Now when we right click on any file in the Windows Explorer we get the same option of Open with NetBeans and the file gets open in the existing NetBeans IDE or if it is not open a new one is started for us.

This makes NetBeans IDE a general purpose editor for me to edit any file in my computer.  

with regards
Tushar Joshi, Nagpur


  1. i am using netbeans 6.9.1 with windows 7, as u have suggested i have stored a new openwithnetbeans.reg in c:\windows

    but could not get the open with netbeans added to the right click of the file, can u help me further

  2. Hi Rejitha,

    You will have to double click the REG file to add thoe entries to the registry. Thanks for pointing this out, now I have updated the post also t mention this.

    with regards
    Tushar Joshi, Nagpur

  3. HI.
    I followed your instructions, W7, NB 6.9.1. But it always opens a new NB. I have worked with registries before so I don't think I missed something.
    I also tested with "hard coding" then file name (-- open "xxxx") but it still opens a new NB (and don't open any file).

    Any advice?

    1. The first thing is it is Nov 2016 and there is NetBeans 8.2 release available, hence I will recommend you shift to the latest edition of NetBeans as soon as possible.

      I can confirm that this works with Windows 7 and NetBeans IDE 8.2

      You can first check by running the command line on a console window first, if the NetBeans IDE is open this command should open the file in the existing IDE instance. If that works on command line then it will also work from context menu.

    2. Thanks for your answer.
      I have also NetBeans 8.0.2. When I wrote my question I thought t was the same issue with that, but it works on NB8. I run an old project on NB6 and a new on NB8, don't remember the reason now :) but I had problems with the new one in the beginning.

      One good thing of having two different NBs is that I can work on two projects without having them interfering each other. But it's perhaps possible to have two instances of NB8 instead.

      But for curiosity, was this not working in NB6. It says that it found a running instance, but then it starts a new.

      But perhaps I should test 8.2. I have to investigate if it supports Ruby on Rails (the plugin).

    3. If you have two versions of NetBeans IDE you can have context menus like

      Open with NetBeans 6.9.1
      Open with NetBeans 8.2

      This command is a basic command line option which opens any file which can be opened by File > Open menu. That means it will work with any plugin like Ruby on Rails also.

    4. Perhaps the problem with NB6 is that I'm running the x32-version of NB on a x64 Win 7. The NB8 is a x64/application.

  4. It still doesn't work with NB 6.9.1, it opens a new instance (but it is in contact with the existing first, the message is "There is a running Window.." or something like that).

    It works with NB 8. I have the same settings for both. But I don't think I will investigate it more. The old project is fading out. I was more curious why it doesn't work.

    Thanks a lot for your help.