To preface this : I am not very experienced with Java. I wanted to write a window application based on Swing. Creating and executing the class file works but after creating the jar file the file doesn't execute when double clicking it. I'm working with SE 1.8.0_131 on Windows 10 (64 bit).
My steps where as follows:
I have created this test file
import java.awt.event.*;
import javax.swing.*;
public class SwingTest {
public static void main(String[] args){
JFrame mainWindow = getMainWindow();
mainWindow.setVisible(true);
}
public static JFrame getMainWindow(){
JFrame frame = new JFrame("Hauptfenster");
// Initialize Window
frame.setLayout(null);
frame.setSize(300, 300);
// Close application on window close
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// Create and add Close-button
JButton exitButton = new JButton("Close");
exitButton.addActionListener(ae -> System.exit (0));
exitButton.setLocation(20, 20);
exitButton.setSize(100, 40);
frame.add(exitButton);
return frame;
}
}
Then I run this command to create the class file:
javac SwingTest.java
This successfully created the class file and I could execute it with the following command:
java SwingTest
I created a manifest file named SwingTest.mf
Manifest-Version: 1.0
Main-Class: SwingTest
Then I run the following command to create the jar file (I wrote this command based on this stackoverflow post)
jar cfm SwingTest.jar SwingTest.mf *.class
This created the jar file but when I double click the file nothing happens (no window or CLI pops or flickers up, no process appears in the tasks)
What did I miss or do wrong to create the executable?
Sorry for the mass of details and thanks in advance