24

As asked and answered here, python has a useful way of deployment without installers. Can Java do the same thing?

  • Is there any way to run Java's jar file without installing jre?
  • Is there a tool something like java2exe (win32), java2bin (linux) or java2app (mac)?
Community
  • 1
  • 1
prosseek
  • 182,215
  • 215
  • 566
  • 871
  • Similar topic : http://stackoverflow.com/questions/664858/how-can-you-package-an-executable-jar-with-a-portable-jre – h3xStream Jul 30 '10 at 13:15
  • Also see [jpackage](https://docs.oracle.com/en/java/javase/19/jpackage/packaging-overview.html). If you don't want an installer, use `--type image` and just ZIP the result. There's also [Graal VM's native image](https://www.graalvm.org/22.0/reference-manual/native-image/), though I don't know if that creates an installer or not (or if that's configurable). Both these options essentially embed the JRE with your application. – Slaw Jan 10 '23 at 10:17

8 Answers8

20

You can use Launch4j for this. Well documented and easy to use. While the resulting program still needs a JRE to run, you don't have to install the JRE on the target system. You can just copy it with your application and tell Launch4j were to find it or just wrap it up with everything else.

haffax
  • 5,898
  • 1
  • 32
  • 30
  • 2
    Where are the JRE file(s)? With Mac I found /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/*, and with PC I found Java/jre6/lib. Do I have to copy all those files? – prosseek Jul 30 '10 at 13:30
  • 1
    You need to copy the two subdirs jre6/lib and jre6/bin retaining the subdir structure. And tell Launch4j where to find it, best as a relative path from the executable's dir. Personally I put the bin and lib dirs in a subdir called jre next to my executable. – haffax Jul 30 '10 at 13:52
6

For creating native executables, you can use Excelsion Jet, which compiles Java to native code. We used it for a project at work, and we had to perform zero modification to the original source code (which targetted Sun's JDK).

barjak
  • 10,842
  • 3
  • 33
  • 47
  • 1
    FAQ: Excelsior JET is not just a packager of Java applications into Windows EXE/Linux binaries. It really compiles your Java class files into native x86 (IA-32) instructions. The resulting executables need the Excelsior JET Runtime to run, but not the Sun JRE. – TheLQ Jul 31 '10 at 01:14
  • "The resulting executables need the Excelsior JET Runtime to run". This is true, but it is also possible to embed this runtime in the generated binary. The binary is then self-sufficient. In this process, I believe it is possible to strip the runtime to keep only the parts that are used in the compiled application. – barjak Aug 02 '10 at 11:36
1

you can embbed the JRE inside your application and create a setup or installation for your application.

mhshams
  • 16,384
  • 17
  • 55
  • 65
1

You can have a look at

http://www.bearcave.com/software/java/comp_java.html

You might get it what you want.

Anindya Chatterjee
  • 5,824
  • 13
  • 58
  • 82
1

You might want to check out how Eclipse does it - it has a native .exe that can use a local (to the installation) JRE.

Tassos Bassoukos
  • 16,017
  • 2
  • 36
  • 40
0

You might be able to get some luck with GCJ - haven't tried it myself.

Noel M
  • 15,812
  • 8
  • 39
  • 47
0

You can do it with NetBeans and a couple of tools. The result is a standalone installer that packages everything you need, so your software can run without installing JRE. It is also completely portable, because it install your software on AppData, that is, it does not need privileges to be installed. Maybe you can even configure the installation path, or you can install it on your own PC, locate the folder and copy it to distribute your software in that way.

Check the Answer I made on different post

Dino
  • 7,779
  • 12
  • 46
  • 85
eniel.rod
  • 855
  • 8
  • 12
0

You can use jlink to create your own customized jre which would contain only those dependencies which are needed for execution. This deployment method is really efficient. please follow **this**link for one such example.

Manish
  • 3
  • 2