Distribute my application jar with a JRE

moin picture moin · Jul 29, 2011 · Viewed 7.9k times · Source

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.

Answer

PhilW picture PhilW · Jul 29, 2011

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>