Mitch Howe
Mitch Howe

Reputation: 55

I can't execute a .jar file by double-clicking

I have tried over and over again to get this stupid .jar file, that does nothing but print text, to execute. Do I need a GUI for it? I'm on a mac.

The code is simply...

public class test
{
    public static void main(String args[])
    {
        System.out.println("This is a test!");
        System.out.println("HelloWorld!");
    }
}

I compiled the test.java file, placed test.class into my Desktop, created a manifest.txt file to make sure that the jar knew test.class was the main file. I wrote

Main-Class: test

into the manifest.txt file

Then I entered

[Macintosh:~] mitchellhowe% cd Desktop
[Macintosh:~/Desktop] mitchellhowe% jar -cvmf manifest.txt Test.jar test.class

and the terminal replied with

added manifest
adding: test.class(in = 341) (out= 186)(deflated 45%)

And the Test.jar file was created ==> Proof of Test.jar creation

However when I double-click to execute it gives me this

How can I fix this? Does it simply need a GUI or am I doing something completely wrong?

****PS****

I am relatively new to programming, I was just curious about how to create an executable jar file. So please put any instructions/criticism in a simplistic format and I will try and reply. ALSO, I want it so I can double-click the file to execute, not order something into terminal (I already know how to run from terminal). Thanks for any help!

Upvotes: 3

Views: 774

Answers (2)

hd1
hd1

Reputation: 34657

You hit the nail squarely on the head -- you need a GUI. Try replacing your System.out.println with JOptionPane.showMessageDialog(null, "Mitch says...", "Hello world!", JOptionPane.PLAIN_MESSAGE); and add import javax.swing.JOptionPane; along with the other imports.

Upvotes: 1

David Paquette
David Paquette

Reputation: 11

Your program does not contain a GUI framework so it cannot open. Check out JavaFX or Swing. I recommend JavaFX due to their new SceneBuilder application, it makes building GUI based applications very easy to learn.

Upvotes: 0

Related Questions