Friday, February 20, 2009

Opening NetBeans projects and files from Linux File Browser

This post covers the topics as follows:
  • How to add Open with NetBeans option in the Ubuntu (Nautilus) context menu?
  • How to open Projects and files from Linux File Browser (in our case Ubuntu Nautilus)?
  • How to use Netbeans IDE as a generic file editor?
As described in the earlier post NetBeans IDE has a command line option --open which allows us to open any file and folder through command line in NetBeans IDE.  Let us check how easy it is to add a context menu option on Linux for this technique.

Adding Open with NetBeans context menu in Linux File Browser
We will open File Browser in Ubuntu which happens to be Nautilus application.  We will navigate to the user home and on the folder icon we will right click to see the context menu.  We will select the option "Open with Other Application..." option.


Open With dialog box will be shown with the "Use a custom command" portion collapsed.  We will click on this portion to get the expanded view of the dialog


The expanded view of the Open With dialog will allow us to type the custom command, which in our case will be 

/usr/local/netbeans-6.5/bin/netbeans --open


The folder will get open in NetBeans IDE when we will press the Open button now.  Not only this but now the option of Open with NetBeans will be added to the context menu for this user. We can check that by navigating to any folder which is a NetBeans project and right clicking it.  Now we can see the Open with "netbeans" option in the context menu.


This makes opening projects in NetBeans IDE a piece of cake.  Not only projects but any folder can be open like this in NetBeans IDE using this context menu.  If the folder is not a NetBeans Project it will get opened like a folder explorer panel which is very handy to work with files.  See how the opened project looks like when opened through this context menu.


Opening files using context menu in File Browser in Linux
Using the same technique we can also add a context menu for files.  Let us right click a file and select the "Open with other Application..." option from the context menu.


Again the Open With dialog will pop up. We will type the same custom command here also.


Now the context menu for files is ready to use.  Let us right click on any file and we get a Open With sub menu, which has many options including the Open with "netbeans" option also.  Now we can use this context menu option to open literally any file from the File Browser.


When a file is opened like this NetBeans IDE provides all the syntax highlighting features for the file type.  This makes NetBeans IDE a general purpose editor for any file.


I also tried to run a simple Java file opened like this in NetBeans IDE and it executed and displayed the output on the output window.

with regards
Tushar Joshi, Nagpur

4 comments:

  1. Is there a way to modify this on shell, because I want to open MP4 with FFmpeg and I have to declare the input and output file.

    ReplyDelete
  2. great man,thanks a lot!!!!!!!!!

    ReplyDelete
  3. not showing any use a custom command

    ReplyDelete
  4. @Ravi Mane, as you can see the post if from year 2009 and the version of Ubuntu used is something which was available that time, I have not tested this with every new release, if you have found some changes, please mention them and also try to find way in your version so other may benefit from that information.
    .
    Thanks for the report.

    ReplyDelete