2

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?

Rajest Kahnna
  • 21
  • 2
  • 6
  • See if this is not what you want: http://stackoverflow.com/questions/2258932/embed-a-jre-in-a-windows-executable – Bruno César Jan 19 '15 at 23:08
  • 1
    As it is possible, it defeats the point of java. It is meant to run with the jvm and be a multi-platform program that only needs to be ran once. It's not hard to install java and lots of computers have it pre-installed. – Dando18 Jan 19 '15 at 23:28

3 Answers3

1

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.

frasnian
  • 1,893
  • 1
  • 12
  • 24
1

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?

Community
  • 1
  • 1
Tomasz Mularczyk
  • 27,156
  • 17
  • 99
  • 146
  • 1
    This kind of defeats the point of java though – Dando18 Jan 19 '15 at 23:27
  • @Dando18 not really; you still have the "code once, run most places" feature for users who do have Java, you just get the added "runs for windows users who don't have Java" feature as well. – Alan Jan 19 '15 at 23:51
  • I didnt mention that there is also program Excelsion Jet, which compiles Java to native code and user can actually run Exe without JRE at all. Hovewer I didnt tryed it by myself. Other than that I have no other ideas. – Tomasz Mularczyk Jan 20 '15 at 10:07
  • Will it run on a Raspi, too? On the Atom prozessor? On linux systems? How many native binaries do you want to provide? – user unknown Mar 20 '18 at 07:06
1

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.

piet.t
  • 11,035
  • 20
  • 40
  • 49
Suraj D K
  • 11
  • 3
  • why we need to Uninstall Java, also my doing this it will works without JRE? – Omore Apr 04 '18 at 18:13
  • 1
    No need to uninstall JAVA but the point is even if you uninstall JAVA the JAR will run by using the java.exe in that particular folder as mentioned and it will work without JRE – Suraj D K Apr 10 '18 at 12:16
  • after creating JAR file "..slash..slashfileName.jar" this jar file will works fine in any other system without using JRE? – Omore Apr 11 '18 at 05:04
  • Yes, I myself tried it and it will work fine – Suraj D K Apr 11 '18 at 06:26
  • thanks I am going to try. – Omore Apr 11 '18 at 11:34
  • one more question if we convert this JAR file into exe file then also we will not face JRE issue, right? – Omore Apr 12 '18 at 12:09
  • I haven't checked that but practically it should work. But I wont prefer EXE file upon JAR because as I know JAR files are more stable than EXE – Suraj D K Apr 12 '18 at 12:50
  • I just test this process, after following above steps I run JAR file in other system which has Java not installed unfortunately, JAR file isn't working. – Omore Apr 13 '18 at 18:47
  • Try using java.exe instead of java alone in the command mentioned above. It will work. – Suraj D K Apr 16 '18 at 07:24