如何将.java或.jar文件转换为Linux可执行文件(没有.jar扩展名,这意味着它不是.jar文件) [英] 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 )

查看:642
本文介绍了如何将.java或.jar文件转换为Linux可执行文件(没有.jar扩展名,这意味着它不是.jar文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索很多类似的帖子,但我仍然找不到我的答案。我想将.java程序转换为Linux可执行文件,而没有.jar扩展名。我该怎么做?我试图使用Launch4j的java包装器,JWrapper,IzPack,使一个.sh,使一个.bat,使用java -jar myFile.jar等运行它,但没有一个工作。一些程序复杂,难以调试。将.java文件或.jar文件转换为Linux可执行文件是否有直接的方法?

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?

我需要将该程序作为一个Linux可执行文件整体传递到另一个将该程序作为参数的程序中。

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

推荐答案

我找到一个解决方案,这正是我想要的几个小时的搜索和尝试。在linux中使用 gcj 命令。

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.

它的工作原理是C ++的gcc和C ++的C ++,将C或C ++程序编译成可执行文件。

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

首先使用终端键入以下命令来安装gcj:

First install gcj by using the terminal by typing:

sudo apt-get install gcj-jdk

之后,cd进入.jar文件所在的目录位于,我们假设.jar文件是myFile.jar,然后执行以下操作:

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

来编译.jar文件。它应该像一个可执行文件一样在命令行中运行,如下所示:

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

./newNameofTheFile

这篇关于如何将.java或.jar文件转换为Linux可执行文件(没有.jar扩展名,这意味着它不是.jar文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆