aspose file tools*
The moose likes Java in General and the fly likes Trouble running JAR files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Trouble running JAR files" Watch "Trouble running JAR files" New topic
Author

Trouble running JAR files

jay ray
Greenhorn

Joined: Feb 11, 2003
Posts: 10
Ok, I was trying to run an application I packaged in a jar file and kept getting the error: "Failed to load Main-Class manifest attribute from <myApp.jar>". I know this is because I need to add the class where my main method resides as the Main-Class in the manifest, but no matter what I add, I still seem to get the error. Also, I upgraded to sdk1.4.1_02 and now when I double click on the jar file, I get nothing. If I try to run it from the command prompt I get the error. Previously, I was getting the error in a gui when I double clicked on the file. Any help at all with these problems would be greatly appreciated!
--Jack Raynor
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Jay,
Welcome to JavaRanch. Everybody seems to have this problem the first time or two they jar up an application. It's important to understand that the main class in the application be listed according to its package and that it be located in the jar directory structure according to its package. For example, if your main class is located in com/jay/main then its package must be com.jay.main and maifest.mf would look something like this:


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
jay ray
Greenhorn

Joined: Feb 11, 2003
Posts: 10
Hi Michael, Thanks for the quick response! Yes, I solved my original two problems. I was including the package name before the class name. I was creating the Main-Class line in the manifest via the command line and the line resided in a text file. Believe it or not, my problem was that I didn't include a carraige return(hit enter) after typing the Main-Class Line and it wasn't being recognized. Now, I'm getting a "class not found" error. I'm guessing it has somthing to do with my classpath. I'm going to mess around with it and check back. Thanks again!
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1824

Before you go messing with your classpath too much, let me say that when you run an executable jar file, it over-rides the system classpath. To set the classpath for a jar, you need to include a "Class-Path:" attribute. (Note the spelling and capitalization...)
Also, the values in the "Class-Path:" attribute are separated by spaces (not : or ; ) and are relative to the directory where the .jar file is.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
jay ray
Greenhorn

Joined: Feb 11, 2003
Posts: 10
Thanks for the help but still no luck. If I try to run it in DOS I get: "exception in thread "main" java.lang.NoClassDefFound" and if I double-click on it I get: "Could not find the main class. Program will exit." I' feel like i've tried just about everything but I know I'm overlooking some stupid minute detail. Any further suggestions?
--jay
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Jay,
Try posting the contents of your manifest and the directory structure of your jar file. Does the jar file depend on any packages outside the core java API? That too could be a problem, and CLASSPATH would come into play.
jay ray
Greenhorn

Joined: Feb 11, 2003
Posts: 10
Hi Michael, Here are the contents of my Manifest:
Manifest-Version: 1.0
Created-By: 1.4.1_02 (Sun Microsystems Inc.)
Main-Class: myApp.MyApp
myApp is the name of the package(created with JBuilder 7) and MyApp is the class that contains my main.
My jar file contains only the manifest and the 5 classes needed to run the app(no audio or image files)
I copied the source code into a .txt, removed the package line at the top, compiled it, and jar'd it up again and it worked perfectly. For some reason it isn't recognizing the package name(or can't find it) in the version created by JBuilder.
--jay
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
In your jar file, were the classes in a directory named myApp? As I stated in my first post, the package structure must match the directory structure.
jay ray
Greenhorn

Joined: Feb 11, 2003
Posts: 10
Thanks a lot Michael! I did't really understand what you were getting at the first time. Problem solved. I really appreciate everyone's help. By the way, now that i've made the .jar file out of my app does anyone have any suggestions on the best way to generate an iso from it so I can put it on a cd. Thanks again!
--jay
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble running JAR files