Over a million developers have joined DZone.

Customize NetBeans Platform Installer to Copy External Files During Installation

DZone's Guide to

Customize NetBeans Platform Installer to Copy External Files During Installation

· Java Zone ·
Free Resource

Start coding something amazing with our library of open source Cloud code patterns. Content provided by IBM.

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()) {
   } 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.

Use this tool to look at the contents of GitHub and classify code based on the programming language used.  Content provided by IBM Developer.


Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}