DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Customize NetBeans Platform Installer to Copy External Files During Installation

Customize NetBeans Platform Installer to Copy External Files During Installation

Sam  Sepassi user avatar by
Sam Sepassi
·
May. 10, 12 · Java Zone · News
Like (0)
Save
Tweet
5.66K Views

Join the DZone community and get the full member experience.

Join For Free

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.

NetBeans Installer (macOS)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Why Great Money Doesn’t Retain Great Devs w/ Stack Overflow, DataStax & Reprise
  • OpenTelemetry in Action: Identifying Database Dependencies
  • The 5 Healthcare AI Trends Technologists Need to Know
  • 10 Books Every Senior Engineer Should Read

Comments

Java Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo