Executable JAR on Ubuntu (NetBeans) Executable JAR on Ubuntu (NetBeans) linux linux

Executable JAR on Ubuntu (NetBeans)


  1. 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.

  2. 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.


You can Java like a native binary on Ubuntu (and other linuxes), it's a feature of the kernel. You need to install the binfmt-support package to give the kernel the hooks to run java in this way.

In Ubuntu open up a terminal and run:

sudo apt-get install binfmt-support

Then make your JAR file executable

chmod a+x yourjar.jar

Then you can run your JAR like any other binary by typing

yourjar.jar


Jar-files aren't first class executables, and they don't become magically executables by changing their executable flag.

If you execute a jar, you run the command

 java -jar YOURJAR.jar ...

It's the same, as if you double click a png file, and expect it to run in a painting program

 gimp YOUR.png

You don't need to make your png an executable one, and it will not solve a problem.

Instead, you have to tell your desktop environment, what to do when double clicking a jar or png-File, and you have to do it on Linux the same way you do it in Windows - maybe the installer on Windows does it for you, because there is normally just on Desktop Environment (Windows) on the OS (Windows), but Linux has Gnome, KDE, XFCE, LXDE, fluxbox and millions more.

And it isn't so sure what you want to do with it. Since jar-files are a special form of packed zipfiles, usually containing a Manifest and the classes, the Archivmanager isn't a false solution, and it is saver to show the content of the archive, than executing it.

Copying the file to windows has no effect. Windows not even has an executable flag, but you shouldn't fiddle with it though. You change your desktop settings, and those can't be moved to windows, and you will not want to.

And if you have the correct settings in your DE, you don't need to tell Netbeans or any other IDE repeatedly, what to do with jar-files.