Packaging a Package
By Geertjan-Oracle on Aug 09, 2006
But now let's say you're going to add your own category. There's maybe a whole new technology you're working on and you've got a variety of templates and you've put them into a new category that you've created yourself. What's a quick and easy way to add a Java Package? Well, our good friends Copy and Paste are often found on the path to happiness. So, assuming your category is called "Wow", the highlighted bit below is what you'd add to the layer.xml file:
<?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="Templates"> <folder name="Wow"> <file name="Package" url="templates/Package.template"> <attr name="SystemFileSystem.localizingBundle" stringvalue="org.netbeans.modules.java.Bundle"/> <attr name="template" boolvalue="true"/> <attr name="templateWizardURL" urlvalue="nbresloc:/org/netbeans/modules/java/resources/Package.html" /> <attr name="templateWizardIterator" methodvalue="org.netbeans.modules.java.ui.wizard.Util.createPackageIterator"/> <attr name="SystemFileSystem.icon" urlvalue="nbresloc:/org/netbeans/modules/java/resources/package.gif"/> </file> </folder> </folder> </filesystem>
The cool part is that the above is literally all you need. Just create a module project, stick the above in the layer.xml and then install the module. That's it. No more is needed. And with that, you have a new category containing a Java Package item that your end user can use just like any other Java Package in any other category.
This question isn't purely hypothetical. It comes from Mohamed El Geish, from Cairo, Egypt, who wrote me an e-mail that included the following: "Every folder in the New File wizard has a file called 'Java Package'. So I created a new folder... and I have currently one entry in it and I want the user to see the Java Package option in my folder."
So, Mohamed, I hope this answers your question. By the way, want to see Mohamed? Click here to see a picture taken in Cairo some months ago... and then read the blog entries just before that blog entry, if you want to find out more about how that picture came about!