Friday, November 03, 2006

Netbeans 5.5 trap

Arghh... I just installed Netbeans 5.5. the other day, to replace the rc2 I used to work with.
Install was smooth, I also re-declared all the libraries I used in a particular project (like javamail, htmlparser, and the postgresql drivers).
Everything compiled fine - and also did run fine - in the IDE only.

I found that in the .jar file I had all the references to those libraries to the local lib/ directory, like lib/javamail.jar etc), but no dist/lib directory, much less of course any library there.

However, in the dist directory NB put a nice little readme file stating the following:
========================
BUILD OUTPUT DESCRIPTION
========================

When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).

To run the project from the command line, go to the dist folder and
type the following:

java -jar "Aware.jar"

To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.

Notes:

* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* If the classpath contains a folder of classes or resources, none of the
classpath elements are copied to the dist folder.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.

Actually, I found that quite nice, to put a readme file to exactly the place where you are looking when you try to find that error.
What was less helpful was, that there was no lib directory and all the FAQ and questions on the mailing lists etc just said, that you probably have not defined your main class in the project's properties.
But I did.

Finally I re-re-re-read the readme file and thought a bit more about the condition:
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
meaning, that if there is just one single entry in the classpath that points to a directory instead of a .jar file not a single jar file will be copied. Not just the one that is - eh - ill defined (i.e. directory instead of .jar, but lets not argue about that), but actually not a single .jar file is being copied that.

So I browsed through all my library definitions, and - of course - there was one that pointed only to the directory, which was fine for the IDE, but not for the .jar builder (it was the javamail, but actually it was my error).
Corrected this to point to the javamail/mail.jar file and everything worked fine.

Cost me just about half a day.

technorati tags:,

No comments: