This tutorial shows you how to write a module that lets the NetBeans IDE, or any other application built on the NetBeans Platform, recognize a new file type. I taught myself how to do this in search for a way to have NetBeans color code and recognize the Cucumber file extension “.feature”.
First you must have the ability to create a new module, so if you just downloaded the NetBeans bundle for Java, Ruby or PHP, then you’ll need to download and install the entire NetBeans bundle because you’ll most likely not be able to create a new module. Assuming you have that:
Creating the Module Project
- Click File -> New Project, In the dialog box under the Categories section choose NetBeans Modules and then under the Projects section choose Module. Click Next. ( see Figure 1 )
- Type in the the Project Name (no spaces), browse to the location that you want to save this module, and make sure to keep Standalone Module checked. Set it to be the Main Project and click Next. ( see Figure 2 )
- In the next panel, fill in the Code Name Base by typing org.myorg.cucumberfiletype. You’ll want to add spaces to the Module Display Name, so its Cucumber File Type instead of CucumberFileType. Last Select the “Generate XML Layer” checkbox, leave the location of the localizing bundle and XML layer as the defaults, and click Finish. The panel should look something like this: ( see Figure 3 )
NetBeans creates the Cucumber File Type project. After it is finished building the project it will open in the IDE. For example, the Projects window should now look as follows: ( see Figure 4 )
Creating the File Type
- Right click the project and click New -> File Type
- In the dialog box do the following: ( see Figure 5 )
- MIME Type text box: type text/x-feature (the word feature is the name of the extension you want)
- Extensions text box: type .feature .FEATURE
- Click Next
- Now type in the Class Name Prefix, in this example it is Cucumber. Browse to an image that is 16×16, it can be a gif or png (maybe other image types to but I haven’t tried them). We will use
for this example. Leave everything else as is and click Finish. ( see Figure 6 ) The IDE will create a bunch of files for you, but you can close them because you won’t have to edit them for what we’re doing.
Your project should now look like this:
In the layer.xml file, you should see the following or something like it:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.1//EN" "http://www.netbeans.org/dtds/filesystem-1_1.dtd"> <filesystem> <folder name="Services"> <folder name="MIMEResolver"> <file name="CucumberResolver.xml" url="CucumberResolver.xml"> <attr name="SystemFileSystem.localizingBundle" stringvalue="org.myorg.cucumberfiletype.Bundle"/> </file> <file name="text-feature-mime-resolver.xml" url="text-feature-mime-resolver.xml"/> </folder> </folder> <folder name="Editors"> <folder name="text"> <folder name="feature"> <file name="language.nbs" url="language.nbs"> <attr name ="icon" stringvalue="org/myorg/cucumberfiletype/cucumber16x16.png"/> </file> </folder> </folder> </folder> <folder name="Loaders"> <folder name="text"> <folder name="x-feature"> <folder name="Actions"> <file name="org-openide-actions-CopyAction.instance"> <attr name="position" intvalue="400"/> </file> <file name="org-openide-actions-CutAction.instance"> <attr name="position" intvalue="300"/> </file> <file name="org-openide-actions-DeleteAction.instance"> <attr name="position" intvalue="600"/> </file> <file name="org-openide-actions-FileSystemAction.instance"> <attr name="position" intvalue="1100"/> </file> <file name="org-openide-actions-OpenAction.instance"> <attr name="position" intvalue="100"/> </file> <file name="org-openide-actions-PropertiesAction.instance"> <attr name="position" intvalue="1400"/> </file> <file name="org-openide-actions-RenameAction.instance"> <attr name="position" intvalue="700"/> </file> <file name="org-openide-actions-SaveAsTemplateAction.instance"> <attr name="position" intvalue="900"/> </file> <file name="org-openide-actions-ToolsAction.instance"> <attr name="position" intvalue="1300"/> </file> <file name="sep-1.instance"> <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/> <attr name="position" intvalue="200"/> </file> <file name="sep-2.instance"> <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/> <attr name="position" intvalue="500"/> </file> <file name="sep-3.instance"> <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/> <attr name="position" intvalue="800"/> </file> <file name="sep-4.instance"> <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/> <attr name="position" intvalue="1000"/> </file> <file name="sep-5.instance"> <attr name="instanceClass" stringvalue="javax.swing.JSeparator"/> <attr name="position" intvalue="1200"/> </file> </folder> <folder name="Factories"> <file name="CucumberDataLoader.instance"> <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/myorg/cucumberfiletype/cucumber16x16.png"/> <attr name="dataObjectClass" stringvalue="org.myorg.cucumberfiletype.CucumberDataObject"/> <attr name="instanceCreate" methodvalue="org.openide.loaders.DataLoaderPool.factory"/> <attr name="mimeType" stringvalue="text/x-feature"/> </file> </folder> </folder> </folder> </folder> <folder name="Navigator"> <folder name="Panels"> <folder name="text"> <folder name="feature"> <file name="org-netbeans-modules-languages-features-LanguagesNavigator.instance"/> </folder> </folder> </folder> </folder> <folder name="Templates"> <folder name="Other"> <file name="CucumberTemplate.feature" url="CucumberTemplate.feature"> <attr name="SystemFileSystem.localizingBundle" stringvalue="org.myorg.cucumberfiletype.Bundle"/> <attr name="template" boolvalue="true"/> <attr name="templateWizardURL" urlvalue="nbresloc:/org/myorg/cucumberfiletype/Description.html"/> </file> </folder> </folder> </filesystem>
How to Install and Try Out Your New File Type
- Right click on the project and click on “Install/Reload in Development IDE”. NetBeans will create and install your new file type only for this session of NetBeans. Once you close the IDE it will delete the “install”, but not the module/project.
- Click File -> New Project and create any type of project you want
- Right click the project you just created and click New -> Other. You will see your new file type in the File Types section.
- You can add default code for your new File Type’s template by editing the CucumberTemplate.feature file. This will be explained in another post, but for now its beyond the scope of this tutorial.
You can add more features to your module at this point, but we will skip that for now. See Creating Features for New File Types
How to Create Shareable Module Binary
This section will allow you to share your new module with others. In order to do this you must create a NBM file.
- Right click on your project and click Create NBM
- You should now be able to view the NBM file in the Files window
- You can now share your module by going to the NetBeans Plugin Portal
I hope you enjoyed this tutorial and that it all worked for you!
Please view our post on the Cucumber BDD NetBeans Plugin to download it and get the latest updates.
Comment, Tweet, Appreciate!












Hi, i need to install Manually a plugins in netbeans, you know how i can do that. Tanks. Sorry about my english.
Comment by salvador — April 23, 2009 @ 5:24 pm
Did you download the plugin? If so, go to Tools>plugins>downloaded
Browse to the location of the plugin and select it. Then click the install button.
Thats all, thats it!
Comment by Chris Gunnels — April 27, 2009 @ 2:47 pm
Hi all,
if i made my own new filetype and i click on
“New File>>Other…”, my new filetype is in group “Other” but it would be better in XML. How can I do that? Do anyone know the answer? Because it’s not in the book or any tutorial i found.
Thanks many times for answer.
Daniel
Comment by Daniel — May 14, 2009 @ 11:45 am
Try this, In the layer.xml file find:
<folder name=”Templates”>
<folder name=”Other”>
…
</folder>
</folder>
Change <folder name=”Other”> to <folder name=”XML”>
I haven’t tested that, but it looks like it will work.
Comment by Chris Gunnels — May 21, 2009 @ 7:39 am
Thanks it’s so clear now, can’t believe i didn’t see that before.
Comment by Daniel — August 11, 2009 @ 6:34 am