21 Apr 2010 03:12 | java ste

Java is really jarring me1. Lame pun intended ;-)

I've just finished making a simple Swing text editor with Java and had a bit of trouble converting it into a JAR file for distribution.

The problem was that even through using the Eclipse IDE to create the file, the JAR didn't include the button icons that I was using. I eventually asked for help after unsuccessfully searching for answers myself, and found that I could only get it to work through using the console to compile the file, and indicating there that I wanted to include GIF files as well:

jar cfm TextEditor.jar MANIFEST.MF *.class *.gif

Looking at the JAR archive, the GIF files were now in there. Great!

But I ran into another problem when I tried to run the JAR. A problem that occurred when I used the console but not with Eclipse. My JAR file wouldn't even run!

I kept getting the error message "Failed to load Main-Class manifest attribute from TextEditor.jar", despite having this as my MANIFEST.MF file contents:

Manifest-Version: 1.0 
Created-By: 1.6.0 (Sun Microsystems Inc.)
Main-Class: TextEditor

That looks right, doesn't it? If you're interested, the code to run the JAR file is this:

java -jar TextEditor.jar

But that wasn't working. And several google search results telling me that defining "Main-Class" would fix the problem — well, let's just say that they didn't do squat for me, because I had already done that.

Investigating further, I discovered that the MANIFEST.MF file in my JAR was missing the Main-Class line. Somewhere in the process of creating the JAR, the Manifest file was losing it's last line.

Eventually, I found the solution in this post on the Sun forums.

I'm guessing that you are developing in windows.

One diference between unix and windows' file system is that text files in unix always have a final linebreak at the end of the file, while windows doesn't need to.

Java, being developed by Sun primarily for the unix comunity requires that the manifest file ends with a new-line.

no new-line, no manifest file.

I added an extra line to the MANIFEST.MF file and suddenly everything began working as expected. One single, blank line!

I'm not going to make that mistake again! :)

Shane's Text Editor (STE v1.01)

So, what was all of this trouble for?

I was working on a text editor that uses Java's Swing components to create a GUI. Please download the file and then post a comment with the following information, to help me improve it :)

  1. What operating system are you using?
  2. Did the application work correctly? If not, what error messages did you see?
  3. If you are using Windows XP or a Mac, please upload screen shots! (I don't have either of those)
  4. Do you have any suggestions for improvements (or things that should be moved/removed)?
  5. If you're nifty with Photoshop, are you willing to create some icons and a logo for a Wikidot-oriented version of this?

Download: STE-1-01.jar 21.15 kB

Edit: Updated the file to v1.01

Submit Feedback
Please rate this page based on the quality and helpfulness of the content to you.

Average 0% rating from 0 votes.

You may also be interested in…


Add a New Comment
or Sign in as Wikidot user
(will not be published)
- +

Add a new comment