Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distribute my application jar with a JRE

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.

like image 687
moin Avatar asked Jul 29 '11 10:07

moin


3 Answers

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>
like image 178
PhilW Avatar answered Oct 08 '22 12:10

PhilW


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.

like image 35
wojciechka Avatar answered Oct 08 '22 11:10

wojciechka


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.

like image 24
Andrew Thompson Avatar answered Oct 08 '22 11:10

Andrew Thompson