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 )

前端 未结 4 2308
醉酒成梦
醉酒成梦 2020-12-15 13:42

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 e

4条回答
  •  被撕碎了的回忆
    2020-12-15 14:19

    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:

    ./newNameofTheFile
    

提交回复
热议问题