Contents

Background

The ImageJ script editor originally would automatically import many useful classes. This provided a clear benefit to writing scripts in ImageJ, as any plugins could be used without troubling the writer to know and enumerate the required classes.

However, there were drawbacks to this method as well. As the imports were not transparent, the user could not know what was actually being imported. During the development of Fiji, it was decided that the broad scope of the autoimport functionality was not robust enough, and could lead to clashes between libraries. Further, it could lead to scripts that are un-executable since dependencies may not be explicitly declared. As these could create situations unresolvable by the user, a dark period devoid of automatic imports began.

Today, ImageJ has a flexible and extensible automatic import mechanism: the ScriptHeader.

How ScriptHeaders works

ScriptHeaders are SciJava plugins, so they can be distributed with any part of ImageJ or Fiji and will automatically be discovered.

When using the script editor to make a script for a particular language, all ScriptHeaders compatible with that language will add their contents to the beginning of the script.

Added lines may be language-specific imports, @Parameter script parameters, comments, or anything else that may be appropriate. For example, in the JRuby ScriptHeader we import an external file. So automatic imports, extra function
definitions, etc... are all handled in imagej.rb.

The result is that the script-writer sees exactly what is added. If they need to make changes of any type, they can do so easily within the editor. When a script is complete, it is then able to be run in any context and not just ImageJ where the auto-imports are present.