How to convert a .java or a .jar file into a Linux executable file ( without a .jar extension, which means it's not a .jar file )

I have been searching for many similar posts about this but I still can't find my answer. I want to convert a .java program into a Linux executable file, without the .jar extension. How can I do it? I am trying to use Launch4j java wrapper, JWrapper, IzPack, making a .sh, making a .bat, running it using java -jar myFile.jar etc. but none of them worked. Some procedures are complicated and difficult to debug. Is there any straightforward way to convert a .java file or .jar file into a Linux executable file?

I need to pass this program as a Linux executable as a whole into another program that takes this program as an argument.


  • I found a solution, which is exactly what I want after hours of searching and trying. It is to use the gcj command in linux.

    It works like gcc for C and g++ for C++ which compile C or C++ programs into executables.

    First install gcj by using the terminal by typing:

    sudo apt-get install gcj-jdk

    After that, cd into the directory of where the .jar file is located, let's say the .jar file is myFile.jar, then do:

    gcj myFile.jar -o newNameofTheFile --main=theMainClassNameofTheFile

    to compile the .jar file. And it should work like an executable by just running it in the command line like this: