Netbeans & jar files

After several months of picking up and putting down my “Teach Yourself Java in 21 Days” book, I am back at it again. I am forcing myself to put my beloved emacs aside and attempting to learn to love Netbeans. It was rough, but I have been able to key in most of the examples and play around with them.

One of the things Netbeans does is create a .jar file isntead of one or more .class files. Jars are Java ARchives. Pretty handy really, and one can run a .jar file like so: java -jar MyJarFile. Unfortunately, that doesn’t seem to be the case with the jars that Netbeans is creating.

While the jar file runs great from within Netbeans, attempting to run it from the command line generates an error:

[bturnip@electric-lash dist]$ java15 -jar IconFrame.jar
Failed to load Main-Class manifest attribute from
IconFrame.jar

If the java15 looks a little odd, it is because I have Java 1.4.2 and Java 1.5 installed on my machine, so I have different softlinks set up in my /usr/bin directory:

[bturnip@electric-lash bin]$ ls -l java*
1 root root 32 Mar 26 14:41 java -> /usr/java/j2sdk1.4.2_07/bin/java
1 root root 30 Apr 6 19:36 java15 -> /usr/java/jdk1.5.0_02/bin/java

Anyway, back to the jar problem. Apparently the problem lies in the way the manifest.mf is generated. If one knows how, the manifest file can be fixed to allow the archive to be run from the command line. That is not currently knowledge I possess.

I have been able to make my code examples run by moving the souce code to a new location and compile it from the command line. This gives me the familiar .class files that can be run from the command line.

UPDATE (9/4):
In the midst of playing around I have found that Netbeans generated jars will run, at least some of the time. I have some test code that runs just fine with the java -jar syntax. The key difference is that the runnable code uses the “main.java” stub that my other, non-running code lacks.

This entry was posted in learning java. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *