Javafx: Create Windows native installer and exe with netbeans 7.2

Source: Internet
Author: User
Tags echo message wix installer netbeans

This tutorial uses the built-in Window application generation function of netbean, so everything is the ant file for configuring the project in netbean.

To generate the. exe file, you must download Inno.

To generate a mis file, download it. Wix toolset

With the release of Java 7 U6 and now Java 7 u7 and Java FX 2.2, you can create a Windows native (native) Installer and application. there are a couple of good guides out there, consider this the Joe Friday version. the steps that follow show how to setup netbeans
7.2 To create Windows native installers and applications. Yes folks (Buddy), turn your javafx application into an EXE !!!!

Note: The versions listed are required for this to work. However, newer versions shound, of course, still work.

Initial setupjava 7 JDK

First, you need to install Java 7 u7 or later. this includes des javafx 2.2 which is now just part of the JDK. no need to go into the installation steps, just a standard install in the default location is fine.
Java JDK 7

Netbeans 7.2

Next you will need to install netbeans 7.2. I use the Java EE version, but the se edition shocould work too.

Netbeans 7.2

Installation Software

To make the EXE file, download and install Inno Setup 5. This makes an installer and creates an EXE. To create an. MSI installer use Wix.

Create a javafx application in netbeans

Of course, before we can create an installer for an app, we need an actual application. if you are just testing, the default javafx application works just fine. to create it, start netbeans then choose file --> new project --> javafx application.
Select a project name and a directory location and you shoshould be all set.

Note: For my example I used a sample app I created called textviewer. In my source files you will see a references to that project.

Before proceeding, make sure you can build and run your application. This shoshould ensure that you have a build. xml file and that everything is working correctly.
Configure netbeans ant Build File

Hooray (great )! You have a javafx app and you are ready to package it for Windows. So to do that, we are gonna need to make a couple of configuration changes to the build. xml file.
Aside: Hey Mike. What is this build. xml file of which you speak? Netbeans uses ant for all of its Java compiling and packaging tasks. ant uses XML files for its configuration. So to make native packaging work, we need to make a few edits
Some of these files. Typically, build. XML is the main configuration file for netbeans 'projects.
Adding a build target

The next step in the process is to add a build target for javafx to the build. xml file. Here is what the code looks like. We may refer back to this again later.
Fxtarget. xml


  <target name="-post-jfx-deploy">
       <fx:deploy width="${javafx.run.width}" height="${javafx.run.height}" 
                 nativeBundles="all"
                 outdir="${basedir}/${dist.dir}" outfile="${application.title}">
          <fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
          <fx:resources>
              <fx:fileset dir="${basedir}/${dist.dir}" includes="TextViewer.jar"/>
          </fx:resources>
          <fx:info title="${application.title}" vendor="${application.vendor}"/>
      </fx:deploy>          
    </target>

To install the target for FX, follow these steps:

  • Get the XML code for the javafx target here: fxtarget. xml. Copy the text to the clipboard.
  • Open your netbeans project.
  • Click on the files tab. This shocould show all the files in your project. Open the build. xml file.
  • Paste the code you copied on the line after the import tag.
  • Next, add an XML namespace for the FX target. add the following text to the project tag of the build. XML file: xmlns: FX = "javafx: COM. sun. javafx. tools. ant"
  • Save the file.
  • Click on the projects tab in the upper left corner of netbeans.
  • Clean and build the project.

<?xml version="1.0" encoding="UTF-8"?><!-- You may freely edit this file. See commented blocks below for --><!-- some examples of how to customize the build. --><!-- (If you delete it and reopen the project it will be recreated.) --><!-- By default, only the Clean and Build commands use this build script. --><project name="TextViewer" default="default" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
    <description>Builds, tests, and runs the project TextViewer.</description>
    <import file="nbproject/build-impl.xml"/>
        <target name="-post-jfx-deploy">
       <fx:deploy width="${javafx.run.width}" height="${javafx.run.height}" 
                 nativeBundles="all"
                 outdir="${basedir}/${dist.dir}" outfile="${application.title}">
          <fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
          <fx:resources>
              <fx:fileset dir="${basedir}/${dist.dir}" includes="TextViewer.jar"/>
          </fx:resources>
          <fx:info title="${application.title}" vendor="${application.vendor}"/>
      </fx:deploy>          
    </target>
    <!--

    There exist several targets which are by default empty and which can be 
    used for execution of your tasks. These targets are usually executed 
    before and after some main targets. Those of them relevant for JavaFX project are: 

      -pre-init:                 called before initialization of project properties
      -post-init:                called after initialization of project properties
      -pre-compile:              called before javac compilation
      -post-compile:             called after javac compilation
      -pre-compile-test:         called before javac compilation of JUnit tests
      -post-compile-test:        called after javac compilation of JUnit tests
      -pre-jfx-jar:              called before FX SDK specific <fx:jar> task
      -post-jfx-jar:             called after FX SDK specific <fx:jar> task
      -pre-jfx-deploy:           called before FX SDK specific <fx:deploy> task
      -post-jfx-deploy:          called after FX SDK specific <fx:deploy> task
      -pre-jfx-native:           called just after -pre-jfx-deploy if <fx:deploy> runs in native packaging mode
      -post-jfx-native:          called just after -post-jfx-deploy if <fx:deploy> runs in native packaging mode
      -post-clean:               called after cleaning build products

    (Targets beginning with '-' are not intended to be called on their own.)

    Example of inserting a HTML postprocessor after javaFX SDK deployment:

        <target name="-post-jfx-deploy">
            <basename property="jfx.deployment.base" file="${jfx.deployment.jar}" suffix=".jar"/>
            <property name="jfx.deployment.html" location="${jfx.deployment.dir}${file.separator}${jfx.deployment.base}.html"/>
            <custompostprocess>
                <fileset dir="${jfx.deployment.html}"/>
            </custompostprocess>
        </target>

    Example of calling an Ant task from JavaFX SDK. Note that access to JavaFX SDK Ant tasks must be
    initialized; to ensure this is done add the dependence on -check-jfx-sdk-version target:

        <target name="-post-jfx-jar" depends="-check-jfx-sdk-version">
            <echo message="Calling jar task from JavaFX SDK"/>
            <fx:jar ...>
                ...
            </fx:jar>
        </target>

    For more details about JavaFX SDK Ant tasks go to

http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm

    For list of available properties check the files
    nbproject/build-impl.xml and nbproject/jfx-impl.xml.

    -->
</project>

You shoshould now see some additional information about your build, similar to this:


Created dir: C:\Users\student\ora\javaone\java1-pub\packaging\native\TextViewer\dist
Detected JavaFX Ant API version 1.2
Launching <fx:jar> task from C:\Program Files\Java\jdk1.7.0_07\lib\ant-javafx.jar
Launching <fx:deploy> task from C:\Program Files\Java\jdk1.7.0_07\lib\ant-javafx.jar
Using base JDK at: C:\Program Files\Java\jdk1.7.0_07\jre
  Skip [MSI Bundler (WiX based)] due to [Can not find WiX tools (light.exe, candle.exe).]
Detected [iscc.exe] version 0.0 but version 5.0 is required.
  Skip [Exe Bundler (based on Inno Setup)] due to [Can not find Inno Setup 
  Compiler (iscc.exe).]
Creating app bundle: TextViewer in C:\Users\student\ora\javaone
\java1-pub\packaging\native\TextViewer\dist\bundles
Result application bundle: C:\Users\student\ora\javaone
\java1-pub\packaging\native\TextViewer\dist\bundles

The following section endeavors (effort) to fix those Skip messages shown above.
Final touches (Polish) to build. xml

There are a couple of other changes you need to make to the build. xml file before your EXE and installer will be built.
Enter your application name

Look at the build. xml file and in the FX: fileset tag, replace textviewer. jar with the JAR file name of your application.

Set the application title and vendor (supplier)

The final thing you must do is set the application title and vendor for the installer. the vendor name on Windows is used to determine what directory name your application is installed under in the Applications folder. the title will of course be used to name
The specified cut that launches your application. You have two choices for set these names, do only one of the following.

  • Choice one, in build. xml edit the FX: info tag and replace $ {application. Title} and $ {application. Vendor} with the strings you wish to use for your application.
  • Choice two, in the nbprojects directory, edit the project. properties file and file the application. Title and application. Vendor key and replace the values defined there with your title and vendor name.

With that, everything for netbeans shocould be configured. Now go to the next section and setup your installer applications.

Installing ing the installer should add Inno Setup 5 to the path

For Inno Setup 5 to create its installer bundle, it needs to be in the path. to check to see if it is in the path, open a command prompt window and type:
Iscc.exe
If the file is not found, then Inno Setup 5 is not in the system PATH variable.

To set the path on Windows 7 select start --> Computer --> System Properties --> Advanced System Properties --> environment variables then choose system variables, path, and then edit. enter the following to add Inno Setup 5 to the path: C: \ Program Files (x86) \ Inno
Setup 5;


Now typing iscc.exe shoshould produce something like this:


This part of the build process shoshould now be ready to go.

Add Wix to the path

Just like Inno Setup, Wix needs to be in your system path for netbeans to be able to use it. add the WIX bin directory c: \ Program Files (x86) \ Wix toolset v3.6 \ bin to the path like you did for Inno Setup. to test to see if Wix is in the path, open a command
Prompt window and type:
Candle.exe
If the file is found and you get help information like you did for iscc.exe, then you shoshould be ready to go.
Building you native app and Installer

With everything configured and ready to go, it is time to clean and build your application. clean and build your project. when you do, you shocould notice the build process takes quite a few seconds longer as the native application files are created.


Netbeans builds a bundle directory under the Code directory. all the native files and Installer can be found here. the directory contains the compressed (Compressed) Installer with. EXE and. msi extension. in addition, a runnable. EXE with the JRE required for
Java app is wrongly ded. For my test application, the bundle (Package) took about 217 mg. The. MSI file was 30 mb and the. exe file was 47 MB.

Run the installer to have your application installed natively (native ). your application shocould be installed in the Start menu under the vendor name you set up earlier. you shoshould be able to run your application just like any other Windows app!

In my testing, for Inno Setup 5 (.exe) the application was installed in the C: \ Users \ USERNAME \ appdata \ local directory and takes up about 140 MB of disk space. for the WIX Installer (. MSI) the application was installed in the c: \ Program Files (x86) \ textviewer
Directory and takes 140 MB.

Troubleshooting

Netbeans build error: the prefix "FX" for element "FX: deploy" is not bound (bounds ).
This is caused by not defining an XML namespace for "FX". See the adding a build target section above for details. (If the namespace cannot be found, add it)

Netbeans build error: Main Application jar is missing.
Problem: Both Inno Setup 5 And Wix are installed and in the path, but no exectuables are being built. Plus, I am getting error messages like the following:

Skip [Windows application bundler] due to [main application jar is missing.]
Skip [MSI bundler (Wix based)] due to [main application jar is missing.]
Skip [EXE bundler (based on Inno Setup)] due to [main application jar is missing.]
Solution: The. Jar name of your application has not been added to the build. xml file. Make sure you have replaced textviewer. jar with the name of your application.

Install problem: the app installed under my user name for my laptop (LAPTOP ).

Solution: You have not set the application. Title or application. Vendor set in either the build. xml file or the nbproject/Project. properties file. See the final touches section above.


Detected policiscc.exe] version 0.0 but version 5.0 is required

This is working for me now. I believe what happened was that I had launched
IDE in which I was running the ant build script prior to installing ISCC, so the IDE wasn' t picking iscc.exe up off the system path. After restarting my ide, everything works great.

Resources

The following resources were used to created this page:

Javafx Docs team: self-contained application Packaging
Igor nekrestyanov: Native packaging for javafx
Textviewer example
Blue sky workshop blog post referring to this how-to. (post any feedback or comments here .)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.