9

How can I distribute my application jar with JRE? I make my executable jar in exe by using launch4j.

My application is a desktop based swing application. I want to make it like an application that if the user has no JRE installed, they can use it by using the embedded JRE. I give JRE with the application and use it. Uninstallation of the application and JRE will uninstall like games.

I understand that if I give the pre-installed JRE with my application, it will happen. I also see the tab JRE in launch4j, but I do not understand which path I will give. This link I also see, but there is no procedure or helpful link is given where the total procedure is defined clearly.

Please give some definite answer. I will prefer if your answer is based on launch4j.

Community
  • 1
  • 1
moin
  • 91
  • 1
  • 3

4 Answers4

5

How do you distribute your application? Do you have an installer?

If you do have a installer, you could bundle any jre with it and configure launch4j to use it.

What I did to recreate your use case:

  1. Create a directory, e.g. C:\temp Copy my jdk from C:\Program Files\Java\jdk1.6.0_23 to C:\temp\myownjdk1.6.0_23 Configure
  2. launch4j to use my JDK: In the JRE tab, enter "myownjdk1.6.0_23" as
  3. Bundled JRE path and I configured to "Only use private JDK runtimes" - although I am not sure if that's really necessary.

I used a JDK, but I'm sure you can do the same with a JRE. Also, I am pretty sure that you must (or can) use relative paths for your bundle (like I did).

This is my configuration file:

<launch4jConfig>
  <dontWrapJar>false</dontWrapJar>
  <headerType>gui</headerType>
  <jar>C:\temp\demoapp.jar</jar>
  <outfile>C:\temp\thing.exe</outfile>
  <errTitle></errTitle>
  <cmdLine></cmdLine>
  <chdir></chdir>
  <priority>normal</priority>
  <downloadUrl>http://java.com/download</downloadUrl>
  <supportUrl></supportUrl>
  <customProcName>false</customProcName>
  <stayAlive>false</stayAlive>
  <manifest></manifest>
  <icon></icon>
  <jre>
    <path>myownjdk1.6.0_23</path>
    <minVersion></minVersion>
    <maxVersion></maxVersion>
    <jdkPreference>jdkOnly</jdkPreference>
  </jre>
</launch4jConfig>
PhilW
  • 741
  • 6
  • 23
  • I do the same thing and it is working,but if i donot give the my java(jre) directory with my test.exe it will not found jre i want to make it more dynamic like games means it will have one exe if i click on it it will extract jre and give some directory choose option and create shortcut option is it possibleby using launch4j.Please reply. – moin Jul 29 '11 at 11:58
  • Well that should be your installer then: let the user extract your package (yourapp.exe, yourapp.jar and yourjdk-directory) to a directory of his choice. This would put the JRE relative to yourapp.exe. One of these might help: http://java-source.net/open-source/installer-generators launch4j does what it should, but it's not a complete deployment/installer package. – PhilW Jul 29 '11 at 12:01
  • Yes.yes you are right actually i want to ask that if you know this option in launch4j or other opensource installer if you can give me some name.Actually i want to make my application like game or other software where one exe is there if you click on this it will automatically extract all and can use it. – moin Jul 29 '11 at 12:09
  • Not sure if I understand you correctly - Do you want to extract and run in one step or is it acceptable for you to have a installation process which does the installation, extraction, creates shortcuts etc.? The simplest variant I can think of right now would be a ZIP file or a self-extracting ZIP file which would extract and (some SFX do that) run your application afterwards. P.S.: This may do what you need http://mark.koli.ch/2009/10/bundle-java-the-jre-and-launch-a-java-app-with-7zip-sfx.html – PhilW Jul 29 '11 at 12:42
  • you saved the day my bro. any idea why just copying the jre folder is not working. i have tried all possible paths. Thank you very much – cjava Jun 23 '13 at 14:54
2

A better strategy is to launch the app. using Java Web Start. Use deployJava.js to ensure a suitable minimum version of Java is available. The user might already have a suitable JRE installed (so no download needed), and will have it there for other Java applications and applets once they choose to uninstall the app.

This does not fit some of your stated requirements, but it is overall a superior option.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • Would the down-voter care to share why this answer was unacceptable to them? – Andrew Thompson Jul 29 '11 at 14:10
  • +1 Even if it's not a perfect fit, [tag:java-web-start] should be at least considered for deployment. – trashgod Jul 29 '11 at 18:59
  • Java webstart pre-requires Java: this looks like the chicken and the egg problem and it is not suitable for the given question. – Panayotis Feb 03 '13 at 11:28
  • @Panayotis That is what `deployJava.js` is for. Please pay attention. As an aside, see ["is 'don't do it' a valid answer?"](http://meta.stackexchange.com/questions/8891/is-dont-do-it-a-valid-answer) in which the conclusion is 'yes, so long as you supply an alternative'. This alternative is better than any of the proposed 'solutions' to install a possibly obsolete and insecure JRE. – Andrew Thompson Feb 03 '13 at 11:30
1

You can also check out BitRock InstallBuilder.

We provide very good support for Java - both detecting if it exists as well as easy inclusion of JRE and building a launcher binary.

You can find more information here: http://installbuilder.bitrock.com/docs/installbuilder-userguide/ar01s17.html#_bundling_a_jre

And Java component/JRE files: http://installbuilder.bitrock.com/java/

With the files from link above, it is as simple as setting a few variables in your project and the installer will work.

It is not free, but if your project is open source, you can apply for a free open source license you can use for creating installers for your application.

Disclaimer: I am one of developers of BitRock InstallBuilder, so I am biased.

wojciechka
  • 598
  • 4
  • 13
0

I have created my own version of the launch4j that allows downloading and installing of required JRE automatically - unattended - (it shows progress for downloading, no progress for installing yet and no option to download the JRE installer to other directory than the installer's working directory - I can add this functionality if anyone is interested in it). Just go to launch4j's "JRE" tab to set your options. Also, this is only for GUI installation and not for console for now. Here you can get it: https://github.com/maztan/launch4j_auto_jre_download

ed22
  • 1,127
  • 2
  • 14
  • 30