Platinum Partner
netbeans,netbeans platform,installer,customization

Customize NetBeans Platform Installer to Copy External Files During Installation

Installer software helps to copy application files to their expected locations. Well, not only to the application folder, but to any place on the system it is run on.

The NetBeans Platform installer infrastructure helps to package and distribute software to any supported machine. The job is routine but it gets a bit tricky when it comes to customization.

For instance, consider the situation that an external file needs to be copied somewhere before installation is completed.

To get started, open the project "helloworld" in the following NetBeans IDE installation folder:

<Netbeans installation folder>\harness\nbi\stub\ext\components\products

After resolving some dependencies (the required libraries reside inside the NetBeans installation dependencies) , open "org/mycompany/ConfigurationLogic.java".

Find the "install()" method. Paste the following code block just before the closing bracket:

File sourceFile = new File(“<path to your target file>");
File targetFile = new File(installLocation,"<wherever you want your target file to be copied>");
// installLocation is a variable containing the location which the application is installing in
try {
   FileUtils.copyFile(sourceFile, targetFile, true);
} catch (IOException ex) {
Logger.getLogger(ConfigurationLogic.class.getName()).log(Level.SEVERE, null, ex);
}
SystemUtils.getNativeUtils().addUninstallerJVM(new LauncherResource(false,targ));

To let the uninstaller finds and removes the external file later, find the "uninstall()" method right under the "install()" method. Paste the following code block just before "progress.setPercentage(Progress.COMPLETE)":

File external = new File(installLocation, "<path to your external file>");
if (external.exists()) {
   try {
   for (File file : FileUtils.listFiles(external .toList()) {
        FileUtils.deleteOnExit(file);
  }
FileUtils.deleteOnExit(installLocation);
   } catch (IOException e) {
}
}
It’s worth mentioning that the FileUtils class provides many useful methods that manipulate files and folders.

This solution described above follows the same path which Ernest used in his bundling the JRE article.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}