- 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 )
- Convert .jar to an application for Windows, Linux & Mac
- 3 Answers 3
- Script which runs JAR application
- Windows registry equivalent on Unix-based systems
- Signing a Windows EXE files
- How can I make a .jar file executable?
- 5 Answers 5
- You must log in to answer this question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- How to convert «jar» to Linux executable file?
- 6 Answers 6
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 )
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.
why you wanna make .sh file for linux only? i guess the beauty of java is cross platform you just need to install JRE and one single jar will run perfectly OK on any OS.
I have tried making a .sh file but it doesn’t work. The reason is because I have a main program that is fixed and written by someone else and I can only pass in my program as a Linux executable (not a .jar) to it. And I am developing it using Java.
@pythonhiew : i guess you can also run jar using command like, java -jar fileName.jar. why don’t you make a bash which run command and up your JAR.
I don’t see why .sh script would be any different than «linux executable», it’s executable as well. Large portion of linux executables are actually scripts — if that doesn’t work then I don’t see how any other executable would work either. Also: Launch4j is for creating native windows executables, I don’t see how that would help you in Linux environment.
Make sure your .sh file is really executable (chmod +x yourfile.sh), maybe that’s the problem. If the tool you are passing the shell script to doesn’t like the .sh ending, just rename it omitting the .sh ending.
Convert .jar to an application for Windows, Linux & Mac
EDIT : Before converting the *.jar file into any other format, I have to modify my code to get user’s OS, and the «documents» folder for each case. I think os.name can satisfy the first request, but can I use user.home + «Documents» for Windows, Linux & Mac (if this folder exists. ) ?
create a simple bash script for linux and deliver it with your jar, then it can be startet via the script
Remember that you CAN publish it as a jarfile. Most Linux users are able to figure out how to run JAR files so you don’t have to wrap it in a shell script.
3 Answers 3
Script which runs JAR application
On Linux and Mac OS you can create a bash script which runs .jar file :
#!/bin/bash java -jar application.jar
Windows registry equivalent on Unix-based systems
There is no Windows registy equivalent on Linux and Mac Os. You can store your configuration in i.e. text files. Machine specific configs are typically stored in the /etc directory tree.
Signing a Windows EXE files
For signing Windows exe files you can try using Microsoft’s Sign Tool.
Here is a similar stackoverflow question: Signing a Windows EXE file
Linux does not neccessarly have an extension. Normally binary files just dont have one. To mark them as executable you set the +x flag on the file, which will grant the file the rights to be executed.
OSX also does not neccessarly have an extension. If you want to install your Program on a Mac, it will be packaged in a folder (on mac these dont look like folders, they look like programs, but on other OSes these appear as folders) with the extension .app .
Launch4j can generate you the binaries for all Platforms, Mac OSX, Linux and Windows.
The «alert» Problem is because your app is not signed. Signing an application means to seal it up so it cant be modified afterwards (it could be modified, but would break the seal). On OSX you can get a developers certificate and use codesign on the .app ( codesign -s «certname» with installed certificate). On Linux you will not have this problems as the programs normally dont get signed (the packages of a package manager normally get signed, this information is lost after installation).
On Windows you also can buy a certificate. After doing so and signing your program, the «alert» might still come given the settings of a user, but it will show the developers or company name instead of unknown (unknown will only appear if not signed or a signed program has been modified after signing).
How can I make a .jar file executable?
I’m trying to run a jar application under Ubuntu, so I installed OpenJDK Java 7 Runtime, but when I open this application I got this message :
The file ‘/home/aimad/Programms/jMerise/JMerise.jar’ is not marked as executable. If this was downloaded or copied from an untrusted source, it may be dangerous to run. For more details, read about the executable bit.
5 Answers 5
You can always run a jar file by doing java -jar JMerise.jar .
However, to make the jar file itself executable, you need to set the executable bit, as the message hints. chmod +x /home/aimad/Programms/jMerise/JMerise.jar will accomplish this.
After that you can do ./JMerise.jar to run it.
man chmod will provide you with information about how chmod works.
Did this ever work? bash: ./bbb.jar: cannot execute binary file: Exec format error for file bbb.jar -> bbb.jar: Java archive data (JAR)
Right click on the file, click on properties, then go to the Permissions tab, and check the box that says «Allow executing this file as a program».
What about if I can’t check that box above, to «allow executing file as a program»? I do check it, but a moment later it automatically gets unchecked!
@user961627 You probably have the .jar file stored on a partition which doesn’t support the executable bit. See Can’t make a file executable for more details.
Since you run your jar application with java -jar application.jar then that means java is on your path. You need two simple things: 1) add an interpreter (which apparently is #!java -jar ) in the first line of your jar file jut like you do that with your shell scripts: echo ‘#!java -jar’ > app.jar cat application.jar >> app.jar mv app.jar application.jar
If you cat the contents of your jar file you’ll see it starts with ex.: #!java -jar PK ^lN BOOT-INF/PK . . 2) add execute attribute by chmod +x application.jar Now you are able to «self-run» it via ./application.jar .
First you’ll need to make sure you have a suitable Java runtime environment on your system. Ubuntu has openjdk in the official repo which is 99.99% combatible with Oracle Java, to install it type:
sudo apt-get install openjdk-7-jre
Next create a file called java-jar-launcher.desktop in ~/.local/share/applications and put the following contents in it:
[Desktop Entry] Type=Application Name=Java Application Launcher Icon=java Exec=/usr/bin/java -jar %U Categories=Application;Java Terminal=False
Next add the following line in ~/.local/share/applications/mimeapps.list :
Now you should be able to just double click jar files to launch them, if nothing happens then right click on a jar file, select properties then go to the «Open With» tab and there you should see «Java Application Launcher», select that.
This method is prefferable (IMHO) because this way you are not giving execute permissions to jar files which can be potentially dangerous. This method will only work in a graphical environment and needs the user to manually double click on the file.
If running a .jar file from the command line works ( java -jar myFile.jar ), but double-clicking it in the GUI does not, and if sudo chmod +x myFile.jar appears to succeed but you still can’t open with double-click, and if right-clicking the .jar file > Properties > Permissions > «Allow executing file as program» does not work (i.e., the checkbox switches back just after you click it), then probably the .jar file is on an NTFS file system, which does not allow execute permissions on a per-file basis. (You may have this problem if you dual-boot, for example, and have a shared NTFS partition between Ubuntu and Windows).
Creating a launcher (as @tusharkant15 describes) will work because behind the scenes you’re executing /usr/bin/java , not the .jar file itself. Moving the .jar file to some other file system that is not NTFS will also work.
You must log in to answer this question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533
Ubuntu and the circle of friends logo are trade marks of Canonical Limited and are used under licence.
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
How to convert «jar» to Linux executable file?
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.
I know how to run «jar» file in Linux, But I need to convert it to (.sh) linux application file. Like (.exe) file in windows
Why not just use a script (.sh) that triggers the jar-file, if you have to mask the application? Why can’t you use the java -jar
6 Answers 6
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.
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.
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.