Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I bundle Java with my Windows application?

I have a Windows application based on Java, that I should like to install with Java bundled. The installation framework is NSIS. The application executable should be guaranteed to invoke the bundled Java, so there's no clash with other Javas installed in the system.

What's the best way to achieve my goal? I haven't tried to solve this kind of problem before, and have little experience with Java, so I don't know which solutions are out there. I think I'd prefer Java to be embedded in the application's executable, if feasible, otherwise I guess Java could be installed along with it (with the executable pointing to said Java).

Edit: This project already generates an executable (.exe), via NSIS. The executable will by default use the system Java, but apparently it'll prefer a JRE in the same directory (i.e. bundled) if present.

Edit 2: The scenario that made me want to bundle Java with this application was that I received an executable for it built with 32-bit Java, which failed (silently) on my system which has 64-bit Java.

like image 689
aknuds1 Avatar asked May 14 '11 18:05

aknuds1


1 Answers

Are you absolutely sure you don't want to use the computer JRE? In most cases it's preferable. You can see here (and the included link) some examples with installers that check JRE number and install it (globally) if necessary.

If you really prefer to include your own JRE in the installer and always use it - what prevents you from doing it? It's just a matter of your main program point having some way of konwing the JRE location and forcing to use it. That depends on how you pack/invoke your Java program. Normally, it would be feasible, perhaps with a simple .bat file - perhaps to be created at installation time.

like image 75
leonbloy Avatar answered Oct 17 '22 13:10

leonbloy