This question already has answers here:
Running java without installing jre?
(8 answers)
Closed 4 years ago.
I made an executable jar file but I want to distribute it to users who may not have Java installed on there computers (Mac or PC). Is there anything I could do anything on my part as the programmer to make sure people without Java can run?
Other than 1) asking them to install Java, or 2) writing your own JVM, the answer is generally no. You have to have a JVM/JRE for your jar file, unless you have a development environment that can create a native executable from your code. But, then it won't be a standard jar file - it will be a native binary (if this development environment just bundles a JVM of some sort into package containing your jar file, with a small executable stub - this would still be putting JVM on their machine - it would just be a bit hidden from a user). So unless you can generate a native binary (not a jar file) from your source, no.
Same with writing something in .NET and attempting to execute it in an environment that does not understand what .NET is, writing something that requires a Python interpreter and trying to run it in and environment without Python, etc.
Running java without installing jre?
Create a folder(lets say PROGRAM) which include folders bin and lib, of your installed JRE.
In my computer I can find them at this path:
C:\Program Files\Java\jre1.8.0_25
Then with Launch4J create a JAR or Exe file of your program inside that containing folder(PROGRAM). Also when you create this file you need to manually select root to these bin and lib folders.
Then user dont need to have JRE installed, hovewer he needs to have folder with program and also bin and lib files in it.
If my english is not enough and these type of solution is what you looking for then heres another source...
How to bundle a JRE with Launch4j?
No need for Launch4j or any other software. Convert your project to .jar file in eclipse then after that put your installed JRE folder in the same folder where your .jar file exists.
Uninstall JAVA from your system then go to JRE folder in that bin folder then open command prompt.
Type:
java -jar ..\..\fileName.jar
i.e java -jar ..slash..slashfileName.jar
Make sure that the JRE installed file and your .jar file is in the same folder.
Related
This question already has answers here:
How can I convert my Java program to an .exe file?
(16 answers)
Closed last year.
Is there a way to create exe files or binaries in java? I've been only able to create java.class files after compiling the code, but I was wondering whether it is possible to create a normal program in a binary or a exe format that I could run without using command java File every time I want to run a program.
The suggested Executable jar files still require a java interpreter to be installed on the system. And as mentioned above, compiling directly into a Windows Executable looses platform independence. Yet it may be desireable to get a more native look and feel during application installation.
For this Oracle/the Java community created JPackage. It wraps your application together with the required JVM such that the whole package can be treated like a native application - regardless whether you want to run on Linux, MacOS or Windows.
You can package all the class files into a .jar file. This .jar file is executable by running java -jar <file>.jar, but most operating systems will allow you, when Java is installed, to double click on the jar file and execute it in this way.
Most build systems (such as maven and gradle) will make it easy for you to create such a file. If you have external dependencies (other jar files), you will need to create a "fat jar" that also includes those dependencies; there are plugins for those build systems to create fat jars.
You can use Launch4J to make an exe file, here you can find more info - https://youtu.be/jPKxqc8Zg-0
I'm looking to make a jar file out some Java code using jar [options] [name] [files] from the command line but it's not recognized.
According to Oracle Jar is part of the JDK. I have both 7 and 8 installed. How do I run the jar function?
I don't have a C:/Java that the Oracle documents show. I've tried running jar from within the JDK directories and with admin rights.
I'm not putting params in yet, want to check I can at least find the jar function first.
Running jar from JDK directory(1.8) http://puu.sh/eoer7/4fcd0ce63c.png
Running jar from System32 http://puu.sh/eoe3X/076d79b4e4.png
You have displayed two installations of the Java Runtime Environment (or JRE). You need to install a Java Developer Kit (or JDK), to get jar. Set your JAVA_HOME to the installation directory of the JDK, and add it to your PATH.
set "PATH=%PATH%;%JAVA_HOME%\bin"
Also, Using JAR Files: The Basics says (in part) JAR files are packaged with the ZIP file format, and you can use tools that can read and write ZIP files to work with them.
If you have a small program, you can run jar file and it will work fine. But if you convert jar file into exe, you still need java to run your exe file, so what's the difference between them and why do some people convert jar to exe?
An EXE is, ostensibly, an executable program that launches the local java to execute the bundle classes.
As you may know, on your computer you can associate certain file extensions with local programs. For example, .doc files with your word processor.
Similarly, .jar files can be associated with Java, so that Java can execute them. The jar file is considered "stand alone" if it has all of the necessary classes bundled within it, and a proper manifest pointing to the startup class.
So, by associating .jar with Java, clicking on it in your environment will launch Java with the given jar file.
An EXE doesn't need that association. It find java on its own with it's own launcher.
The next step is that you can actually bundle the JRE in to an EXE, so you don't even need to have the user install Java as a pre-requisite. But that's a different process.
People commonly use Java executable wrappers for two reasons - 1. to simply deployment for environments without a JVM, and 2. To make sure the exact Java runtime used for developing the application gets used to run the JAR. However, the practice is not that much widespread.
Java archive or jar is an archive of compiled java byte code and resources which can be run on a java virtual machine. ".exe" is a windows extension for directly executable code mostly used by installers or programs that do not need to be installed. I think your "people" are talking about installers.
An Exe file is an executable file that can be executed in Microsoft OS environment.
Jar file is container of Java Class files, including other resources related to the project. Jar file can be executed only if Java run time environment.
The JavaTM Archive (JAR) file format enables you to bundle multiple files into a single archive file.
The .class files compiled from java files, can not be launched directly. That is why it is needed to be converted to exe before it can run in a windows environment.The usual way to start a java program by batch file is not a convenient way. So inorder to avoid this difficulty we need to convert jar files into exe file.
Also converting it to exe. enables the program to run by simple double click on the program, instead of having to compile it with an IDE or through the JVM.
All that the exe will do is to start a jvm with your app, something like this: "java -jar app.jar".
I want to create a executable jar file of a small game that i wrote in java and make it playable in any machine with simple double click like exe file. My question is do you need to install java runtime first in order for executable jar file to work or can it work on a machine without any java installed as well?
No it can't. However, clients do not require the JDK, the JRE would do.
You can make your jar declare its own main class and have users double click it normally like an exe file or create a bat file in Windows.
It requires a JRE instance to be installed on the host machine. This is because JAR files are actually executed via a command line like (in Windows):
java -jar ...
This means that somewhere on your system the java.exe executable should be reachable, either by including its folder in the PATH (Windows) or replacing java with its full path.
Also, most likely you will need to have all the runtime Java libraries to be hosted on the system, as the JAR file containing the application you want to run is not supposed to contain all the Java API libraries. They are also part of the JRE package.
My explanation is tied to Windows for the sake of examples, but it can be extended to any OS.
Do you need to install java runtime first in order for executable jar file to work?
Yes, of course. To run Java .jar files first you need to have installed at least the JRE (run time environment). The JDK (development kit) is a superset of the JRE and will also work for running .jar files.
Can it work on a machine without any java installed as well?
No, as mentioned above, at the bare minimum the JRE must be installed.
You have to have a Java runtime environment (JRE) available on the machine unless you use a tool that performs ahead-of-time compilation (AOT, which is contrast to the usual Just-In-Time). Such tools are available (such as Excelsior JET), but they have a number of downsides, including cost and the fact that a precompiled Java application is a regular executable and will only run on one operating system. I've seen some installers that will detect whether a JRE is installed and launch the Java installer for the user if not.
Yes ! of course, JRE is required and it is not compulsory for JDK to be installed. Since, the main class is defined in JRE for .jar files, it is necessary to have JRE on your machine. I tried with Windows OS.
Actually you can bundle JRE within your exe file with several java .exe wrappers.
Here are few of them JSmooth, Launch4j, Jar2Exe.
I have exe file called Myapp.exe. Now I want to convert .exe to jar file. That jar file should also work in NON JAVA system. I don't have any idea to implement it. Can anyone please suggest me how to do it?
Direct conversion not available !!!
because they are in entirely different platforms.
Meeting your requirements is impossible for two reasons.
1) You cannot change an EXE to a JAR file.
2) You cannot run a JAR file on a system that doesn't have Java installed.
If you want to run something on a (Windows) system with no Java installation, it needs to be an EXE ... or something else that doesn't require Java.
(It might help if you explained why you think you need to do this. Perhaps there is an alternative set of requirements that are not impossible to meet.)
why i am doing all those stubs is for making my jar has to work in java not installed system.
It needs to be an EXE then!
I have an jar.It is working fine in java installed system.My task is to Bundle jre inside jar(Not along with jar(i.e we can put jre and jar in same folder to run a jar as given in following url mindfiresolutions.com/… ))Because i have to give jar file only to client,in such a way that they can use this Myapp.jar in non java system also.But,i don't know how to bundle jre inside jar.I Don't how to run jre inside jar?
Ermm ...
Is it possible?
No. You cannot embed a JRE inside a JAR file in any way that would allow it (the JAR file) to run your Java code without first installing Java. (And installing Java would defeat the purpose of embedding the JRE ... of course.)
But what you can do is create an EXE file which has a JRE and a JAR embedded in it. And there are tools for doing this. Here's the canonical Question on how to do it:
How can I convert my Java program to an .exe file?
I think you need to read the Oracle documentation on what a JAR file really is, and how Java programs are normally executed. That will help you understand what is feasible ... and what is nonsensical.