Convert JAR file to EXE file so that you don't need Java to start the program?

pr
9

Question is in the title. I was thinking of something similar to Minecraft, where I just leave the VM together with the program so that you don't need to have Java installed to start the program.

Does anyone know how to do that?

Re

"Converting" is rather nonsense. It makes more sense to deliver the program with an installer that includes the required JVM. At most there's then a small launcher as .exe. The usual installer generators like NSIS or Inno Setup can certainly do that.

There are a bunch of converters (e.g. Launch4j) which basically convert everything into a self-extracting EXE or something similar. Freighting - that makes things slow above all.

On operating systems with a sensible packaging system, the matter is irrelevant anyway - you enter a dependency on Java and it goes automatically. But we're obviously talking about Windows…

Oh yes, of course there's also the option Native Image of GraalVM: https://www.graalvm.org/reference-manual/native-image/

But this is not intended for this purpose, but for something like web services that are packed in containers anyway.

pr

Thank you,
I'm new to the topic and I'm concerned with the fact that there are users in my circle of friends who want to use the application but do not want to install Java for security reasons.
Since I don't want to learn a new programming language because of this, I'm busy running Java programs on computers without Java.
How do you create such an installer with NSIS or InnoSetup, is that difficult?

Re

NSIS is not difficult and there are ready-made solutions for various problems.

Packr may also work for your purpose: https://github.com/...bgdx/packr - but that doesn't build an installer itself. In that case, however, you would need a very simple standard installer that doesn't even have to deal with the Java problem.

pr

That means I do an installer with NSIS that uses packr to take the JVM with me. I'm just installing packr and have a look at how it works

Re

That would be the idea. Or. You first build the thing with packr and then let NSIS build the simple installer for it.

I haven't tried it myself, but it looks like a reasonably reliable solution.

pr

I read a little bit into packr. With packr I rebuild the jarFile so that the JVM is directly included. Then I take NSIS and the new Jar file and can then use it to build an installer with a subsequent EXE file to run.

Re

Packr does not make a "Mega-JAR". That just builds a folder structure that contains the original JAR, JVM and an exe launcher (and that's a good thing - I wouldn't want my well-tested artifact to be rebuilt for distribution). The NSIS then installs precisely this folder structure.

As mentioned in the documentation, there's now also jpackager that does a similar thing. But only from JDK 14.

pr

All right, thank you very much first. I hope I can get in touch with problems or anything else, because as I said, I'm new to this topic ^^

pr

Perfect, that worked with Packr, with NSIS I'll try the days, but with Packr, it worked after I read a little bit. That was exactly what I needed, thank you very much! (get the most helpful answer as soon as I can ^^)