Geertjan's Blog

  • October 5, 2005

Binarize JAR Files -- Without Coding or Typing Anything Anywhere

Geertjan Wielenga
Product Manager
I never had the Hibernate JAR files until a few days ago. And I didn't download them from the Hibernate site. And NetBeans doesn't bundle the Hibernate JARs. And they aren't available from the NetBeans Update Center. So how did they get into my Library Manager (click to enlarge)?

Well, there's a very cool wizard—the J2SE Library Descriptor wizard—which is one of the 6 fantastic new file-level wizards in NetBeans IDE 5.0 (click to enlarge):

When you use this wizard, you can bundle a set of archive files (including, for example, Javadoc). The wizard lets you select an existing library in the Library Manager (and provides access to the Library Manager so that you can add the library if it doesn't exist) and then creates a plug-in module containing the archive files, together with a J2SE library descriptor—which registers the library in the Library Manager (this, for example, is the descriptor generated for Wicket):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library PUBLIC "-//NetBeans//DTD Library Declaration 1.0//EN" "http://www.netbeans.org/dtds/library-declaration-1_0.dtd">
<library version="1.0">

And this is generated in the module's layer.xml file:

<folder name="org-netbeans-api-project-libraries">
<folder name="Libraries">
<file name="Wicket.xml" url="Wicket.xml"/>

Really, no exaggeration, there's no typing or coding or anything required anywhere when going through this process. (Even the library name and display name are generated for you.) And at the end—after choosing the Create NBM menu item—you have an NBM file. An NBM file (NetBeans Module) is a NetBeans module packaged for delivery via the web. The principal differences between NBM files and module JAR files are—an NBM file is compressed, an NBM file can contain more than one JAR file, an NBM file contains metadata that NetBeans will use to display information about it in the Update Center, such as the manifest contents, the license, etc, and an NBM file is typically signed for security purposes.

Where the ability to bundle libraries in modules and expose them in Library Managers is really powerful is when you're creating project templates and samples. These, when exposed in the New Project wizard, are much more accessible than when they are installed in your filesystem. By putting them in the New Project wizard, you not only have easy access to them but, because they need to be in an NBM file in order to be in the New Project wizard, are also very easy to share with others. A case in point is support for Wicket, which is the scenario outlined in detail in the NetBeans Project Template Module Tutorial. So, let's say you've put a project sample for Spring (or anything else) in the New Project wizard. Your first instruction to users is: download the Spring JARs from the Spring site. Wouldn't life be a lot easier for everyone if you just provided those JARs in the same NBM that contains the sample?

So, a NetBeans user (no idea where he in the world he is) sent me the Hibernate JARs that are shown in the first screenshot above. He used the NetBeans Project Template Module Tutorial (and gave some useful feedback) to create the NBM file and then sent it to me. Now that I have these JAR files, I can use the Hibernate classes (plus, thanks to the Source Editor, I have code completion and can display Javadoc while coding). Not bad. And all without coding or typing anything. Anywhere.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.