How to convert "jar" to Linux executable file?

36
November 25, 2021, at 1:50 PM

I know how to convert "jar" to windows executable file(.exe). But I want to know how to convert "jar" to Linux executable file(.?). I have searched google but didn't get exact answer what i want, help to do this.

Answer 1

I want to know how to convert "jar" to Linux executable file(.?).

Linux does not have executable files the same way that Windows does. In Linux we have binaries and scripts. Scripts are ran with an interpreter; languages like Ruby and Python. Binaries are files of compiled code, they can be libraries or entire programs. Both binaries and scripts can be executable.

To make a program executable in Linux, type this into the command line.

$ chmod +x myProgram

Alternatively you can open file preferences and set executable in the permissions section.

Since Linux does not have .exe files or an analogue, we'll have to work something else out. Linux and other Unix like Operating system have a shell called bash; often called the command line or terminal in reference to Linux and Mac. We want to create a file that can be run as our entire program, instead of having to call $ java -jar myProgram.jar. To tell bash to start a script environment for a file we use a hashbang. This is the first line of the file which instructs bash were to look for the interpreter to send the rest of the file to. For a bash script, like Batch Script on Windows, we would start the file with #!/bin/bash. The path after the #! (hashbang) tells bash were to look for the interpreter. For a .jar make the hashbang #!/usr/bin/java -jar and then cat the .jar to the file with the hashbang. This can be done all from the terminal in Linux.

Create a file with the java jar hashbang.

$ echo "#!/usr/bin/java -jar" > myBin

We have written the hashbang as a string to the new file myBin.

Write the jar to the file.

$ cat my.jar >> myBin

The >> appends the jar to the receiving file.

This will create a file that has the bash hashbang and the jar appended to it. Next set myBin to executable and try to run the program.

$ chmod +x myBin
$ ./myBin
Answer 2

Create a sh wrapper file with following content and make it executable:

#!/bin/bash
java -jar <your-jar>

Optionally add some vm arguments.

Perhaps there are some tools that could generate such a file, but is is little effort to do it manually I reckon.

Answer 3

You can always run a jar file by doing java -jar myFile.jar.

However, to make the jar file itself executable, you need to set the executable bit, as the message hints. chmod +x /path/to/your/file/myFile.jar will accomplish this.

After that you can do ./myFile.jar to run it.

man chmod will provide you with information about how chmod works.

Source: How can I make a .jar file executable? on AskUbuntu. Answer by Gary

Answer 4

Try the packr tool. It will help you create a native Linux executable file from your Java application.

READ ALSO
Twilio Autopilot&#39;s custom channel Memory payload

Twilio Autopilot's custom channel Memory payload

I'm creating a web chat and I need to integrate an assistant using Twilio Autopilot, I use Autopilot's custom channels as follows:

43
&quot;Requiring Wifi permissions limits app availability on TVs that support only Ethernet&quot; warning in Android Studio - can anything be done about this?

"Requiring Wifi permissions limits app availability on TVs that support only Ethernet" warning in Android Studio - can anything be done about this?

I'm developing an Android app (a game) that supports phones and TVs too, and can play multiplayer via LAN (WiFi or Ethernet) or WiFi Direct

71
Trying to pull from a folder of images

Trying to pull from a folder of images

Hi first time here and I'm very new to coding

9