I have a small (Swing) JApplet that runs perfectly in Eclipse: it contains a label, two buttons and a menu, with minimum user interaction (when choosing a menu item, the color of the container changes).
I converted this to a .jar:
- I right clicked the class name (Sw3.java)
- Selected “Export”, then “Java”, then “JAR file”
- Next, I chose current project name as resource to export, doubled clicked the “Default package” underneath it, selected desired class name from the list of classes in the right (Sw3.java)
- Next, I ticked “Export generated class files and resources”, selected the export destination as “JAR file” and placed it in “Documents” under the name “Sw3.jar”. I also selected “Compress the contents of the JAR file”.
- In the next screen I checked “Export class file with compile errors” and “Export class file with compile warnings”
I heard the right way to obtain an exe file is to convert a .jar into .exe so I used the “Launch4j” application with the .jar obtained previously:
- In the “Basic” panel: specified OUTPUT FILE: C:\Users\jerry\Documents\Sw3.exe and the JAR file: C:\Users\jerry\Documents\Sw3.jar.
- Process priority NORMAL
- Header type: GUI
- MIN JRE Version: 1.0.0
- I pressed the “wheel” and chose Project.xml and got a succesful confirmation message.
I have JRE installed, so the .exe should work, but it doesn’t work. What did I do wrong? I would start by investigating if the .JAR was correctly obtained, is that a good approach and how would I check that? Thank you!
PS: Upon being advised to use JFrame instead of JApplet, I did that and still nothing happens when I double click the .exe in order to open it. This makes me suspect there is something wrong in the steps I described.
Add a main method to your applet to put it inside a
JFrame:In the Eclipse JAR exportation dialog, after the “JAR Packaging Options” screen (the one with “Export class files with error and/or warnings” that you mention above), click next (and not finish). Choose “Generate manifest file” and enter the fully qualified (i.e. including package) class name of your main class: