Errors running jar files

I have problems running a jar file that I have created, I get an error message as follows: "Could not find the Main Class. Program will exit."

Another jar file gives me a message:"Fatal exception occured. Program will exit."

I suspect I am not creating the manifest file correctly, I hope someone can help as there is not a lot of info available on this subject.

Here is an example of what I have done:

c:javaGreg003
in the above directory I have the following files: Main.class Ball.class Paddle.class
pongGame.html bounce.au and error.au MANIFEST.MF

my manifest file contains:
Manifest-Version: 1.0
Main-Class: Main

I made sure that I included the carriage return in the manifest file before saving it.

This is what i entered to create the jar file:
c:javaGreg003jar cmf MANIFEST.MF pongGame.jar Main.class Ball.class Paddle.class BasicPong.html bounce.au error.au

This creates the pongGame.jar file in the directory but I cannot run the program by double clicking the icon.It gives error "Fatal exception occured.Program will exit". I also tried to run it by entering java -jar pongGame.jar
This gives me the following error: "Exception in thread "main" java.lang.NoSuchMethodError: main

This program runs perfect when run the normal way in internet explorer.
I also tried a few programs that dont use an html file but also did not have any success, I have looked at other messages in this message board and tried a few things without success. Hope someone can help!!

Comments

  • : This program runs perfect when run the normal way in internet explorer.
    : I also tried a few programs that dont use an html file but also did not have any success, I have looked at other messages in this message board and tried a few things without success. Hope someone can help!!
    :
    Is that program an applet? u can't run an applet using 'java' command, you have to modify the program into swing or awt application.
  • : : This program runs perfect when run the normal way in internet explorer.
    : : I also tried a few programs that dont use an html file but also did not have any success, I have looked at other messages in this message board and tried a few things without success. Hope someone can help!!
    : :
    : Is that program an applet? u can't run an applet using 'java' command, you have to modify the program into swing or awt application.
    :

    Do you have written a Manifest-File to identify the main class inside of your JAR-Archive? If you've done so, your main class does not have a "public static void main (...)" method, to initialise itself, in this case I guess it's an applet, and applets can only be started from a webbrowser.
    best regards,

    sebastian mohrenstecher
    executive secretary
    net::allies

    www.net-allies.de
    info@net-allies.de

  • Thanks for all the advice received, the program is an Applet, I will try modify it as an awt and try again. How are programs packaged that run in a web page, I have often played some java games in a web page that just open automatically??
    I have also tried a program that runs in the DOS console, after making the jar file I also get the same error messages. Is there any websites that explain how to make jar files including what all the error messages mean. This will be good if I can find a few example programs to practice with. Thanks a lot!

  • Applets literally "[italic]start()[/italic]" automatically when the web page is opened -- the browser invokes [code]Applet.start()[/code]

    In truth however, that behavior is up to the implementation -- the browser can decide how and when to call [italic]init()[/italic] and [italic]start()[/italic]; but I don't think there's a browser or viewer out there -- including the Applet Viewer -- that doesn't just invoke start() as soon as the page is displayed. I've never heard of a container that doesn't do this. But it is not worth ignoring -- if that makes sense -- that this [italic]is[/italic] up to the implementation. As Verisign puts it on thier sight right now, Security "remains" a top priority for most users; and the ability to prevent Applets from automatically loading will likely be an evolutionary behavior that [b]browsers[/b] integrate -- the user will get some buttons somewhere to "start" the rich media or Applet or whatever the browser calls it and they will control when these things run.

    Don't despair!! The news is: The browser is not the real network client -- that is up to you to write, my friend. Check this out: A browser is an HTML Application client (or at least somethong close to that nomenclature). HTML is an application that is running over the TCP network that is the internet. NOTHING FORCES you to USE HTML. Java is your entry point to the WWW3 -- MyWWW or whatever -- when a client uses a crappy old "browser" to hit your www site, you can give them the link to get your client. They at that point begin the experience you have coded. I _know_ you're going to ask me "how is this done" and the answer might be (yes it [italic]can[/italic] vary): At www. xx .com, have a link to a WebStart application (see -- this could be an Applet instead -- and in fact may be better as an Applet). From here they can load a signed Java application (it sure has to be secure) and you can provide them whatever you want in the ensuing window -- as you probably know: networking live information, and rich GUIs and all the 2D and even printing in the standard SDK. Basically, you could open a whole new browser if you want.

    You can find a lot more useful information in the Java Tutorial than many people would seem to have you believe. The SDK API documentation alone would leave you hanging, but that combined with the tutorial gives you enough information to do _anything_ in the Java language from Applets to full J2EE environments to desktop apps and simply eveything -- you would't even need to buy any books. ;)


    To find what you need to know about the [b]manifest and Jars[/b], check the java tool docs in the API bundle for the Jar tool -- follow the "see also" links too: In particular, the "The Jar File Specification" contains the Manifest specification. The 5.0 online docs are here:

    http://java.sun.com/j2se/1.5.0/docs/index.html

    link to the JDK Tools and Utilities (did you know you can click on the big image at the top of tha page?.....). Navigate to the jar tool then the reference page for Linux or Windows. -- If you're on a Mac you can hit either page (the Windows page is fine); the main difference is that they "hard code" the platform file and path delimeters into the documentation -- it'll say: -classpath pathpath1;pathpath2 for Windows but on the Mac the ";" would be I think the colon and the "" is a semicolon. These properties can be pinched on your current system using System.getProperty with the keys: "path.separator", "file.separator", and "line.separator". The Manifest specification and Jar file specification tells you most of the stuff you're talking about.

    [b]Just in case[/b], the "basic JDK tools" documentation -- which is javac, jar, the keytool and all that -- is here:

    http://java.sun.com/j2se/1.5.0/docs/tooldocs/index.html#basic

    -- look for [b]jar[/b], and on the right click on your favorite platform -- you could try different ones to keep Sun on thier toes. At the very end of that page is the link to The Jar File Specification which itself contains the Manifest specification.


    In case you're not hip to this stuff yet, Sun is working on implementing a new compression scheme for jars that should be in the 5.0 release (that's thier name for the 1.5 release if you'r old like me and a bit confused by it); it's called Pack2000 or something. It might be nice to know about all that stuff. You will find that ongoing on the JCP site: http://jcp.org/en/jsr/detail?id=200 Note that this is not fundamental to getting your Applet out the door today; it's just a tip on what other people are up to so you know you're not working in a vacuum.

    OK! Good luck.
    Peace,
    - Steev.
  • http://www.myjavaserver.com/~sscotties/javasrc/jar/jarred.html

    This is a page I found to be somewhat useful, I hope it helps you.
  • Just to give some feedback, I have finally got the jar files to work, the mistake i was making is in the manifest file, i now just keep it a simple one line command eg: Main-Class: Hello2
    I also noticed that when trying to make a jar file using the ECLIPSE editor I got errors. I dont think ECLIPSE is at fault it must be something I am doing in error there.
    I get the best results by using the DOS command line.
    Thanks again for everyones help here, Im sure if anyone with jar troubles reads the advice given here they will have success
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories