Java linux bin file

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.

Источник

How to work with .bin files

I want to install JDK 1.6 on my Lubuntu OS. But it is some specific .bin file instead of tar.gs for linux — Java SE Development Kit 6u45. UPDATE: After following suggestion, I catch next:

error: Failed dependencies: /bin/basename is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/cat is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/cp is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/gawk is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/grep is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/ln is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/ls is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/mkdir is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/mv is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/pwd is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/rm is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/sed is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/sort is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/touch is needed by jdk-2000:1.6.0_45-fcs.x86_64 /usr/bin/cut is needed by jdk-2000:1.6.0_45-fcs.x86_64 /usr/bin/dirname is needed by jdk-2000:1.6.0_45-fcs.x86_64 /usr/bin/expr is needed by jdk-2000:1.6.0_45-fcs.x86_64 /usr/bin/find is needed by jdk-2000:1.6.0_45-fcs.x86_64 /usr/bin/tail is needed by jdk-2000:1.6.0_45-fcs.x86_64 /usr/bin/tr is needed by jdk-2000:1.6.0_45-fcs.x86_64 /usr/bin/wc is needed by jdk-2000:1.6.0_45-fcs.x86_64 /bin/sh is needed by jdk-2000:1.6.0_45-fcs.x86_64 rpm: RPM should not be used directly install RPM packages, use Alien instead! rpm: However assuming you know what you are doing. error: Failed dependencies: /bin/sh is needed by sun-javadb-core-10.6.2-1.1.i386 

Источник

Читайте также:  Linux опции команды find

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 command anyway?

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.

Источник

How to Convert a Java File to an Executable? (Windows, macOS, Linux)

How to convert a Java file to an executable

Java distributions can be a significant pain to figure out — especially when you have no clue how these files work on the backend of your native operating system. While there are multiple ways to package Java files, most are too arduous for beginners.

Читайте также:  Linux mint cinnamon mate xfce разница

Now, you could pay someone to do it on your behalf, but that’s no fun — especially when you’re a programmer.

Since converting java files to executables isn’t a one-step process, you’d have to delve deep into the technical stuff to understand it truly.

Convert Java file to an executable

With that out of the way, the best method of converting Java files into an executable is by using the built-in functionality of an IDE like IntelliJ IDEA. While this shaves off some technical flexibility, it’s plenty for beginners and regulars.

Hence, it’s recommended you download and configure the IntelliJ IDEA by creating and opening your project from there. This IDE is available on Windows, macOS, and Linux, thereby making it perfect for our use case:

Operating System IDEA Source
Windows Download
macOS Download
Linux Download

This article will primarily focus on creating executable JAR files for your specific operating systems. For simplicity’s sake, we will use built-in IntelliJ IDEA methods to achieve this goal.

Table of Contents

Creating A Project On IntelliJ IDEA

1. Installation Setup

Once you’ve downloaded the above file, it’s finally time to install it and give the IDEA a go.

Windows Install

Here’s what you need to do for Windows :

  1. For starters, click on the setup and press Yes to the Windows Prompt.
  2. Next, select your settings, and don’t forget to add IntelliJ IDEA to the path . Here’s what it’ll look like:

Installation setup on Windows

  1. Add the bin folder to the PATH and hit Next > .
  2. Now, press Install, and wait for the process to finish.

Linux Install

The installation steps you’d need to take will differ vastly if you’re on Linux. Luckily, we have those listed for you down below:

  1. Once the directory has been changed, enter the following command to extract the installation file from the downloads directory.
  1. Replace the with the actual path of the downloaded installation file. For example, an IDEA file stored in the Downloads folder will look something like this:
sudo tar -xvzf ~/Downloads/ideaIU-2020.3.tar.gz

Mac Install

The installation process on macOS is pretty simple compared to the rest. Just drag the .dmg file from the Downloads Folder to the Applications Folder, and you’re good to go!

2. Creating a Project Out of the Java File

Once you’ve downloaded and opened IntelliJ IDEA, it’s time to create a new project, so you can load all your files up to convert them to an executable later on.

With that said, follow the steps below for all platforms:

  1. Launch IntelliJ IDEA, and choose New Project in the Welcome Screen. If it doesn’t show up for you, select File > New > Project instead.
  2. Next, wait for the New Project menu to open up and choose your configurations. You can also select a language that does not come packaged with IDEA.

Making a project out of the Java file

  1. Now, select the Build System , and choose a JDK from the list. If you don’t have one, click the download button.

Once the project has been built, open its path and add your code files as needed. This will work on Windows, macOS, and Linux since IntelliJ IDEA is the same on all platforms.

Building Java Applications

1. Converting a Java File to JAR

Once your project is ready and running, it’s time to export it into the JAR config, which can be later processed into a .exe file.

Читайте также:  Kali linux virtualbox wifi usb

With that said, here’s how you can do it:

Building Java applications

Building Java applications

Building Java applications

  1. Lastly, select PATH , and any optional Class , and extract it to the target JAR .

Doing so will make a JAR file that can not only help you convert regular JAVA files to .exe, but also the JAVA Class ones.

2. Convert JAR to Windows exe

You will need to download an application called Launch4J to make this work. Just click on this link , and press the download button.

Once the application has been downloaded, follow the below steps:

  1. To start, open Launch4J and select the output file location.
  2. Next, enter the PATH to your JAR file and fill the rest with your preferred configurations.
  3. Now, click on the Gear button, and name your file to click save.

That’s it! Just open the new exe file you’ve created, and you’re pretty much done.

3. Convert JAR to macOS Executable

Just like Windows, you’d need the aid of some third-party packages to make this work.

Here are all the steps you need to follow:

cd jar2app sudo ./install.sh /usr/local /usr/local/jar2app ~/Downloads/pathg.jar // replace jar path with your jar

4. Convert JAR to Linux Executable

Unlike Windows, Linux does not feature executable files. Rather, you get files that are just a bunch of compiled code or scripts run with interpreters’ help.

To make JARs work on Linux, you’d have to create a bunch of hashbang commands.

$ echo '#!/usr/bin/java -jar' > myBin
  1. Now that we have written the hashbang as a string to the new file myBin. It’s time to write the jar to the file:
  1. Lastly, set the myBin file to an executable by using the following commands and run the program:

Conclusion

To sum up, in this article, we showed you how to convert a Java file to an executable on Windows, macOS, and Linux.

Essentially, it would help if you could convert your JAVA project into a JAR file. Once that’s done, it’s about issuing the commands in their respective operating systems. As mentioned, Linux doesn’t have executables, so you’d be creating a gimmick instead.

Luckily, the process is pretty simple once you get the hang of it since most of the complex stuff is pre-handled by IntelliJ IDEA. Alternatively, you could try your luck at Eclipse if IntelliJ IDEA is too much for you.

Save the resultant JAR file in an accessible PATH, so you won’t have to find it later.

If the steps mentioned above cause an error, try rebooting your device or computer or perform a clean reinstall of the error-causing software.

Lastly, let us know in the comments:

  • Were you able to create a JAR file from your JAVA project?
  • Have you been able to find a more straightforward be-all-end-all fix?
  • Which kind of software are you trying to make?
  • Are there any other points or helpful information you believe we should’ve mentioned?

Feel free to share this article amongst your friends and peers, so they don’t have to rack their brains to convert JAR or Java files into executables.

Источник

Оцените статью
Adblock
detector