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 2289
醉酒成梦
醉酒成梦 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:15

    Another simple trick to convert a jar to a Linux executable is just putting a shebang before the jar file.

    Say we have a hello.jar file.

    $ java -jar hello.jar
    hello world!
    

    You can create an executable in following steps.

    $ echo "#! /usr/bin/env java -jar" > hello
    $ cat hello.jar >> hello
    $ chmod +x hello
    

    Then, you will be able to execute the hello file directly.

    $ ./hello
    hello world!
    

提交回复
热议问题