Sam has posted 4 posts at DZone. View Full User Profile

Customize NetBeans Platform Installer to Copy External Files During Installation

05.10.2012
| 3964 views |
  • submit to reddit

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.

Published at DZone with permission of its author, Sam Sepassi.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Winston Dehaney replied on Fri, 2013/05/24 - 2:23pm

Ok, this sounds nice. I wanted to be sure about one thing though. Is this the same way to include any folder at all in the installation process? What happened is that I was using the NetBeans Platform Application module to create a desktop application for a class project. I have my pictures in my modules suite folder, but when I try to make an installation file it doesn't use that folder so my application ends up not showing some pictures. So I was wondering if this would automatically include these folders. Don't know if my request is clear.

Winston Dehaney replied on Mon, 2013/05/27 - 9:29am

OK, I'm going to try it out

Sam Sepassi replied on Wed, 2013/10/02 - 1:52am in response to: Winston Dehaney

Sorry mate, i didn't get notified of your comment. Well if i understand correctly you have files which netbeans platform doesn't include in your installation package, right ?

Well you must include your resources such as pictures, inside your java packaging structure rather than folders external to your java program. By doing this, platform will surely put the resources inside the installation package. 

The method i explained, is targeting the situation where its is not possible to include specific resources inside java packaging structures. So this acts a hack.

Sam

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.