Packaging a Package

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">
<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!

Comments:

Thank you so much, your answer is a great help indeed.

Posted by Mohamed El-Geish on August 11, 2006 at 09:36 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today