Can I bundle some additional files with my module? If so, how can I find those files to use them from my module?
Note: These pages are being reviewed.
Sometimes you need to bundle some additional files with your module (for example native libraries or native executables).
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
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
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-filesto rebuild/re-copy that library (i.e.
<target name="release" depends="compile-lib,projectized-common.release"/>and then create your own
compile-libtarget 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.
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
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