Geertjan's Blog

  • April 27, 2011

Installing the JRE via an Application's Installer via Windows

Geertjan Wielenga
Product Manager
In contrast to Ernest's excellent instructions, these below assume that (1) you are creating your installer on Windows and (2) you'd like your installer to be used on Windows only. Hence, these instructions are more limited, but also simpler, focusing purely on the Windows scenario.
  1. Go to your JDK installation and copy the JRE somewhere else, separately (e.g, "C:\\Program Files\\Java\\jre"), so you don't end up messing up the JDK you're actually using to run, for example, NetBeans IDE.

  2. Go to C:\\Program Files\\Java\\jre\\lib and run:
    pack200 -J-Xmx1024m rt.jar.pack.gz rt.jar

    Now go into C:\\Program Files\\Java\\jre\\lib and delete the "rt.jar".

  3. Go to C:\\Program Files\\Java\\jre and select the "bin" folder and the "lib" folder. Right-click and ZIP the selected folders. You'll end up with "jre.zip".

  4. Put unzipsfx.exe (which you can get from the NetBeans sources, in "nbi/infra/build/jvm" or from somewhere online) into the same folder as where the jre.zip is found. Run this:
    copy /B unzipsfx.exe + jre.zip jre.exe

    The result of the above is that you have "jre.exe", a self-extractable zip archive, which you can run and then you'll find the "jre" installed on your system. We now need to bundle this jre.exe into the installer, via the Ant script that configures the installer, as outlined in the next step.

  5. Replace "create-bundle" in build.xml in the IDE's "harness/nbi/stub/build.xml" with the following:
    <create-bundle root="${output.dir}/registry-temp" platform="${platform}" 
    <component uid="${main.product.uid}" version=""/>
    <property name="nbi.bundled.jvm.file" value="C:\\Program Files\\Java\\jre.exe"/>

  6. Put this right at the end of "install()" in ConfigurationLogic.java, which is within "harness/nbi/stub/ext/components/products/helloworld/src/org/mycompany":
    File javaHome = new File(System.getProperty("java.home"));
    File target = new File(installLocation, "jre");
    try {
    FileUtils.copyFile(javaHome, target, true); //FileUtils is one of the NBI core classes, already imported
    } catch (IOException e) {
    JOptionPane.showMessageDialog(null, "Cannot copy JRE");
    // to add uninstaller logic:
    SystemUtils.getNativeUtils().addUninstallerJVM(new LauncherResource(false, target));

    And, in the "uninstall()" method, add this right before the last statement:

    File jre = new File(installLocation, "jre");
    if (jre.exists()) {
    try {
    for (File file : FileUtils.listFiles(jre).toList()) {
    } catch (IOException e) {

    You have now specified how and when the "jre" will be installed by the installer wizard.

  7. In your application, e.g., in "nbproject" of your application, create a ".conf" file with, among other things, this entry:

    And register the conf file in the application's "project.properties" file like this:


    Now you have specified that the application will use your jre.

When you right-click the application and choose "Package as | Installers", an executable file will be created. When you run the executable, an installer starts, the JRE is unbundled to a temp folder, the installer uses that JRE, and a copy of the jre is made to a folder named "jre" within the root folder of your application, where the "jdkhome" setting in the .conf file finds it. That JRE, i.e., a private JRE within your application's root folder, is then used to start up the application.

In this way you can distribute your application to users who do not have the JRE installed on their system.

Join the discussion

Comments ( 22 )
  • Sony C Thursday, April 28, 2011


    Thank you for this, it is excellent. Can the same technique be used to add other executable programs in another directory?

    If so, how would one reference the directory within the app once it is installed?

    Thanks !

  • David Thursday, May 12, 2011
    Notice that you also need to add the default_userdir in the application conf file with a line like :
    However I encountered troubles with the generated app because I lost my custom splash screen and my application name which is set to the default "Netbeans Platform 7.0" name. I have to check if it's related to that (it works fine when running it inside Netbeans)
  • guest Sunday, July 10, 2011

    Hi Geertjan,

    I'd like to push the question raised by Sony C. I'd also like to bundle an external application (a xampp distribution) within the installation dir of my netbeans plattforma application.

    Unfortunatly I didn't find any information about how to do that but somehow it should be possible as Netbeans IDE self ships a tomcat server with it.

    I hope you can point me to a document describing how to accomplish this.



  • Geertjan Sunday, July 10, 2011

    SmilingJ, just follow the same steps above and replace JRE with your own app.

  • guest Wednesday, June 13, 2012

    Hi Geertjan,

    I have followed above steps and I am able generate jre folder under my application after installation. But unfortunately the application is not starting as well as not giving any error.

    Also I found that the size of the application becomes too big. Is it correct.

    Let me know


  • Bhan Wednesday, July 25, 2012

    Hi Geertjan,

    We planning to make a commercial application based on netbeans platform. Our end user machines (mostly windows and linux) will not have any jre pre-installed on it. Using NBI and the approach you and Ernest have mentioned we can bundle JRE to be private jre's for our application. Are there any licensing restrictions from oracle which will avoid us from embedding JREs within our application? I read through licensing part of JRE at oracle and am sort of confused. It would be great if you can advise us if its legal to bundle JRE with our commercial application.

    Thanks a lot for your guidance.

  • Geertjan Wednesday, July 25, 2012

    No licensing restrictions. Would be great if you'd send me a screenshot and description of your commercial application to geertjan dot wielenga at oracle dot com!

  • Ann Maybury Sunday, December 9, 2012

    I am trying to follow this using Windows7 and Netbeans 7.2.1.

    When executing the pack200 in the CMD window, I get an exception

    "Exception in thread "mai" java.io.FileNotFoundException: rt.jar(the system cannot find the file specified: rt.jar

    at java.util.zip.ZipFile.open(Native Method).


    at com.sun.java.util.jar.pack.Driver.main(driver.java 233>

    I am new to java and netbeans, but a search of my disks reveals that no java.util...

    Where do I get it and how should I ann it to my java or netbeans?

    Is the CMD window the right place to be trying this?

  • Ann Maybury Sunday, December 9, 2012

    I solved my last problem. User error. Please ignore.

    However, I have spent a lot of time on the web trying to find unzipsfx for windows. No luck. Your article refrences building it, but I have had no luck finding the source.

    Can you tell me where to get it?

    Ann Maybury

  • Geertjan Monday, December 10, 2012

    Where does the article tell you that you need the unzipsfx source? You don't.

  • guest Sunday, December 16, 2012


  • guest Thursday, February 7, 2013

    Thanks, I am able to bundle jdk and third party applications.

    Is it possible to bundle two jres (32 and 64 bits)?

    Can the installer resolve which jre to include ?

    Asutosh Gopinath

  • guest Friday, February 8, 2013

    i got my answer here:


    asutosh gopinath

  • guest Thursday, August 22, 2013

    Hi Geertjan,

    I have tried all the steps above (as well as referred to the wiki). However, when I run the generated installer, it fails saying that the JVM is not compatible. The verbose output has a line "unpack200 not found" just after the entire bundled JRE has been successfully extracted.

    Can you tell me where I might be going wrong here?



    PS: I would like to mention that your blog is absolutely great! I have referred to it a number of times and mostly my issues have been solved. Thanks for maintaining it!!

  • guest Monday, August 26, 2013

    I found the issue myself!! The log for the installer is quite unhelpful when it comes to errors - its tough to figure out what is the exact command creating an issue. Turns out I had bundled the JRE incorrectly - with a parent folder jre containing the bin and lib.


  • Peter Hansson Monday, February 2, 2015

    Just wanted to let people know that there's an omission in this blog: You need to make sure to set file permissions as well when you copy the JRE into its permament location. So it is not enough only to do FileUtils.copyFile(). See this DZone blog for more information: http://netbeans.dzone.com/including-jre-in-nbi

    If you do NOT do this you'll experience error message when you later start application saying that the JVM cannot be found or is not compatible.

    So check your file permissions.

    (yes, if you're ONLY on Windows then you would never notice this issue)

  • guest Tuesday, April 28, 2015

    Wrt those asking for the same on Mac:

    See this RFE: https://netbeans.org/bugzilla/show_bug.cgi?id=250103

    While we wait for this to be fixed you can follow the instructions in the RFE and get it to work right now. You'll need:

    1. Knowhow about how to check out, correct and build one of the core NB projects ("NBI Engine project").

    2. Knowhow about how to use your own custom nbi-engine.jar (from step #1) instead of the one that comes with NB itself. Instructions will differ between Ant and Maven based projects.

    It will be too lenghthy to explain all this in the comment thread on Geertjan's blog. Sorry. :-(

  • Geertjan Tuesday, April 28, 2015

    Feel free to write a blog entry or article about it yourself and reference it here!

  • Peter Hansson Saturday, August 1, 2015

    One more thing: When you bundle a JVM with your application the installer does not take the size of the unpacked JVM into account when it calculates the need for required disk space.

    Luckily NBI has a variable that allows you to modify (add) to the disk space that NBI *thinks* is the correct one. In build.properties set this property:


    Now the installer will add 100 MB to the number it has calculated on its own. I use 100 MB in the example because that is roughly the size of an unpacked JVM on most platforms.

    (Geertjan: I know I keep adding hints in this blog entry and I'll need to write my own blog someday with all tricks and tips but until then I kind of abuse your comment track to keep track of these things. Probably not cool but better than not publishing it all)

  • guest Friday, September 4, 2015

    Hello Geertjan Wielenga,

    Thanks a lot for your valuable post. I followed all the step mentioned by you in this post to Installing the JRE via an Application's Installer. I have reference via https://platform.netbeans.org/tutorials/nbm-runtime-container.html for NetBeans Platform Runtime Container. When I installed application on machine my application installed successfully but application not able to run/execute.

    I hope for your valuable response.

  • Geertjan Saturday, September 5, 2015

    Here's the mailing list, join it and ask your questions there: dev@platform.netbeans.org

  • Gilles Thursday, December 10, 2015


    First some comments that I noticed in this tutorial:

    1. You can find unzipsfx.exe in the zip file available here https://netbeans.org/downloads/zip.html (I used the one ending with platform-src.zip

    2. Add: import javax.swing.JOptionPane; on top of the ConfigurationLogic.java file

    3. As the my.conf file replaces the default one, it needs also to contain at least the same content than the one produced by an installation without following this tutorial. (Search for *.conf in the installation directory)

    4. I noticed that the installer automatically suggests Program Files or Program Files (x86) on a 64 bit target computer depending on the architecture of the jre.exe. Note that I used the architecture of the unzipsfx.exe according to the one of the jre version. (I work on a 64 bit computer, but not sure that this is required.)

    Question: In my case this tutorial worked, except that when I run the uninstaller, there is a message saying that Java isn't found. Does someone know why?


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.