2

I'm trying to download the file http://algs4.cs.princeton.edu/code/algs4.jar and launch it with Jar Launcher (the default application). However, I'm getting this:

enter image description here

Following https://discussions.apple.com/thread/4827576?tstart=0, I've also tried to use Archive Utility; this appears to create an algs4.jar.cpgz file but I'm not sure what to do with it. How can I open the JAR file?

  • What error messages did you see on the Console? – Allan Aug 22 '17 at 9:52
2

Even though the error message says to check the Console I couldn't find anything useful there. However if you try to run the JAR file from the Terminal you get this error:

no main manifest attribute, in ./algs4.jar

This error means that the JAR file is missing the "Main-Class" parameter in its MANIFEST.MF file. The Main-Class parameter tells the Java runtime which class is the Entry Point, i.e. which class to run first when launching.

You can add this parameter using the Terminal. First of all download the JAR file from the Princeton website, then run the following command (assuming the JAR file is in your Downloads folder):

jar ufe ~/Downloads/algs4.jar TestAlgs4

This command updates the MANIFEST.MF file within the JAR. Once that is done the JAR file should run from the Finder or the Terminal successfully.

Screenshot of algs4.jar running

Having said all that, you only get the error if you try to run the JAR like an executable. I don't think you're meant to do that. You are meant to just place the JAR file somewhere the Java runtime can find it, and then refer to it in the code you write as you do the exercises in this book. There are clear instructions here on what you are supposed to do with the JAR file here: https://algs4.cs.princeton.edu/code/

  • 2
    That last paragraph is the real answer to this XY problem, I’m glad OP provided the background info to be able to research this properly, and thank you for reviving this question! – grg Mar 29 '18 at 20:29
  • What whould I need to type for other jar files? I get "could not find or load main class ufe" – existing person Aug 1 at 5:19
  • Most likely that means the JAR file is a library and not meant to be run directly. – Alistair McMillan Aug 1 at 19:13
0

As the error message says, you can check the Console (/Applications/Utilities/Console) for error logs. You could also open a Terminal window and run the jar from the command line, which should cause any errors to output into the terminal. If your jar is in your downloads folder you would run:

java -jar ~/Downloads/algs4.jar

Once you have the error, if you can't figure it out, update your question and we can try to provide more information.

You must log in to answer this question.

protected by Community Nov 19 '18 at 19:24

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .