java可执行文件的扩展名,如何将.java或.jar文件转换为Linux可执行文件(没有.jar扩展名,这意味着它不是.jar文件)...

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:

./newNameofTheFile

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值