Custom Code & Resources Step
Custom code is configured on the "Installer->Screens & Actions->Custom Code" step.
Entries in the custom code are used for
specifying additional libraries that can be used in scripts and expressions of screens, actions and form components.
developing new types of actions, screens or form components with the
install4j API. See the help topic on using the API for more information.
Before you start to develop a new action, have a look at the available actions and screens. If it is just a few lines of code, you can use the "Run script" action to enter them directly into install4j. If you would like to collect user input, most use cases can be solved with a form screen.
An alternative way of adding your beans to the install4j is packaging them as an extension. In that case, you can select them directly from the standard registry dialogs instead of having to go through the "Search in custom code" menu entries when adding beans to the installer.
including resource files into the installer. Resource files are arbitrary files like DLLs, external executables or text files that have to be available before the "Install files" action has run. All class files are packed into a single
user.jarfile, archives and resource files are extracted to the
usersubdirectory in the working directory of the installer. You can access a resource file named
file.txtwith the following expression in custom code:
new File("user", "file.txt")
To specify resource files in text fields in the installer configuration, use the
To load native libraries in custom code, do not use
System.load(..), but rather
Util.loadNativeFromResources(...)to load the library in the same class loader that loads scripts. For example, if you have added a native library
jni.dllto your custom code, you can load it in a "Run script" action by calling
The following types of custom code locations are available:
Class or resource files
For simple actions, screens or form components that do not depend on other classes, it is easiest to insert their class files directly, especially if you build your installer extensions together with your application. Anonymous inner classes will be included automatically. If you select a resource file, for example an image, it will be added to the top-level directory of the custom JAR file and will be available via
With this type of entry you can add an entire directory. Make sure to select a classpath root directory, otherwise your classes cannot be loaded.
Use this type of entry to add all JAR and ZIP files in a selected directory.
Use this type of entry to add a JAR file. Files that are present in both the custom code as well as the distribution tree will not be packaged twice. Files that are also present in the distribution tree can be freely added to your custom code, they will not increase the size of your installer. The compiler checks the source path of included files to determine if they are already present in the installer.