I'm writing a simple Swing application in NetBeans and doing so on an Ubuntu machine for the first time.
As many of you know, NetBeans automatically creates executable JARs for projects that are "set as main".
On Windows, you can double-click an executable JAR and it automatically invokes the JRE and runs the app. In Ubuntu, double-clicking the .jar file causes the file to be opened in the archive manager instead. In order to run my JAR, I either have to right-click it and select "Open with OpenJDK Java 6 Runtime" or launch it from the command line.
From the command line I get no problems whatsoever. However, when I try launching it from the right-click menu, I get an error that reads:
The file MySwingApp.jar is not marked as executable...
So I have 2 questions:
Thanks for any helpful suggestions!
However, to make the jar file itself executable, you need to set the executable bit, as the message hints. chmod +x /path/to/your/file/myFile. jar will accomplish this. After that you can do ./myFile.
Right click the . jar file, and open properties. Now in the properties menu, open the 'Permissions' tab. Enable the 'Allow executing this file as program' checkbox.
Right click on your Java Project and select Export. Select Java -> Runnable JAR file -> Next. Select the Destination folder where you would like to save it and click Finish.
You will need to manually tweak your build process to get the jar file marked as executable in Netbeans. Go to your project root and open build.xml. The header has instructions on adding to the build process. There is a target, "-post-jar", that is called after the jar is built. You'll need to make that target and use Ant's chmod task to modify your jar. Once you do that it will occur every time you make a jar file in that project.
It will run fine on your friend's Windows machine, as long as he has a JRE installed.
Here is a thread about running jars using double click in Linux.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With