Geertjan's Blog

  • August 9, 2006

Packaging a Package

Geertjan Wielenga
Product Manager
When you look in the IDE's New File wizard, you might notice that many of the file categories (each of which provide templates of one kind or another) have their own "Java Package" item. Makes sense, because when you're working with, for example, the JUnit templates, you don't want to look around for the Java Package item, so it makes sense to keep it together with the JUnit templates in the JUnit category, as well as virtually every other category that needs it.

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">
<folder name="Templates">
<folder name="Wow"><file name="Package" url="templates/Package.template">
<attr name="SystemFileSystem.localizingBundle"
<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"/>


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!

Join the discussion

Comments ( 1 )
  • Mohamed El-Geish Friday, August 11, 2006
    Thank you so much, your answer is a great help indeed.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.