Can I bundle some additional files with my module? If so, how can I find those files to use them from my module?

Apache NetBeans Wiki Index

Note: These pages are being reviewed.

Sometimes you need to bundle some additional files with your module (for example native libraries or native executables).

Bundling External File With Your Module

NetBeans provides a simple and straightforward way to bundle whatever files you want into a module project:

  • Create a folder in your project root directory called release/ (note this means the project root — the directory containing src/ and nbproject/ and MANIFEST.MF, not the source root directory of your module project!)

  • Put anything you want bundled with your module in that directory or a subdirectory of release/

  • The entire subtree of this folder will be included in your cluster and bundled into your module’s NBM file

  • Note that if what you are adding is a native library (DLL, .so file, etc.) there is a specific place to put this

  • If the thing you are bundling can change (for example, you are bundling a library you wrote, and you may make changes to that library and recompile it), you may want to override your module’s release-files to rebuild/re-copy that library (i.e. <target name="release" depends="compile-lib,projectized-common.release"/> and then create your own compile-lib target that rebuilds the library and copies it somewhere under release/ in your module project.

The result is:

  • the files you are bundling are included in your module

  • Note that this does not mean they will be inside your module’s JAR file (that would not be useful)

  • They will be bundled with your module’s JAR file and will be in a findable location at runtime (see below).

Note: If you are bundling third party software which has its own installer there is a way to run that installer during module installation.

Finding External Files At Runtime

Now your module includes the files you need. You still need to get access to them at runtime.

To do that, use InstalledFileLocator. That is a class which can find a file which was installed by a module. You simply give it your module’s code-name (the thing you typed when you created the module, which looks like a package name) and a relative path (i.e. not including the release/ directory):

File emulator = InstalledFileLocator.getDefault().locate(
    "javacard/bin/jcre.exe",
    "org.netbeans.modules.javacard.referenceimpl",
    false);

Always handle the case that the user (or disk crash, whatever) might have deleted it.

If you are wondering why you don’t just find the directory NetBeans is installed in and look in that directory, see the background information about clusters