This has been getting a lot of traffic on the mailing list. It's true, Java does not have a real clear deployment story for JavaSE apps. It relies on you to set the main class and classpath in the manifest and arrange all the JARs by itself, and doesn't give much guidance. When you come at this from an IDE point of view, where you're used to the IDE dealing with these implementation details (as it should!), it's often confusing when you try to run from the command line or send the program to someone else and it doesn't work.

So here's the story as far as I understand it - I'm sure one of our developers will soon be writing up a more complete guide. When you create a JAR, you have to do two things in the MANIFEST in order for it to run on the command line:

  • Specify the main class in the Main-Class entry. NetBeans does this for you, it looks something like this:

    Main-Class: org.me.mypackage.MyMainClass

  • Specify the location of any JAR files on the classpath in the Class-Path entry. So if you have your lib JARs in a lib subfolder, your MANIFEST should have this:

    Class-Path: lib/jhall.jar lib/mail.jar

Then to run from the command line you go to the location of the app JAR file and run something like this:

java -jar "JavaApplication1.jar"

Now the good news: NetBeans 5.0 Release Candidate (not the Beta) does this automatically. All the JAR files are transferred over to the dist/lib folder and the classpath is set up automatically. Just zip up the lib folder to send it out.

Now, some people want more than this. They want to package everything, including multiple JAR files, in one JAR file and just send that one JAR file out there. There's an open-source program called one-jar that does this, and we actually considered using this, but there are too many instances where you don't want to do this (licensing of some JARs on classpath prevent it, a lib JAR is used by several different app JARs so you'd have to package it in each app JAR, etc.).

But obviously some users want this... So....

Why doesn't someone do a plug-in module to integrate one-jar? Doesn't seem like it'd be too difficult. You'd have to create a wrapper project for the one-jar binary, modify the Packaging page of the Project Properties dialog box to give an option to use one-jar and specify any additional options, and write some different instructions in the build script.

Maybe I'm being naive about how easy it is, but it seems to me that Eclipse users constantly write plug-ins for this type of nice-to-have functionality, and if this was Eclipse, we'd have had a community-contributed plug-in long ago. With all the new module developmen support, the old excuse of "It's too hard to write plug-ins for NetBeans" just doesn't fly any more.

Time for NetBeans users to step up to the plate!

Post a Comment:
Comments are closed for this entry.

This blog copyright 2009 by johnc