Scripts can now be discovered from JAR files

Tags: #<Tag:0x00007fb87b6d6b00> #<Tag:0x00007fb87b6d67b8>


A perennial question of script developers has been: can I distribute my scripts inside a JAR file? For a long time, there was no solution. More recently, there is fiji/Script_Launcher, which provides a hacky way to write an ImageJ 1.x plugins.config that launches scripts embedded in the same JAR file.

However, the right way to do this is really for SciJava Common to take care of discovering scripts within JAR files for you. There was already code that essentially did it, in the form of the Script Editor’s script_templates. I have now adapted and generalized that code so that scripts within the scripts directory of each classpath element (including JAR files) get discovered automatically. With this scheme, we no longer need the ImageJ-1.x-specific plugins.config files, but instead everything is handled natively by the SJC discovery mechanism.

The relevant commit is scijava/scijava-common@0fa97cde8. If you want to try out the code, you can download the latest 2.57.0-SNAPSHOT. I have not substantially tested it yet, although there are passing unit tests exercising the feature.

Using self written Jython modules in ImageJ
New Plugin for realease
Best practice for git and plugins as Imaging unit member

I have tested the new feature with some Jython scripts and it works fine.

But I’m wondering why one needs to create a folder called scripts and not Scripts like in the Fiji plugins folder.

As I’m using maven to manage dependencies for my Jython scripts, the ImageJ Maven Plugin is used to move the jar to ImageJ. Because there is no plugins.config it is placed in jars and not in plugins. Luckily the new discovery mechanism still finds my scripts.


Thank you! Very glad to hear that!

I chose scripts mainly for consistency with other folders, including script_templates, jars, plugins, luts, etc.

Note that the plugins folder is only for compatibility with ImageJ 1.x. Ultimately, with ImageJ2, all JARs can live in a single folder, since there is no distinction between “plugin” libraries and “supporting” libraries. All of the ImageJ2 plugins which ship with ImageJ2 (imagej-plugins-*.jar) also live in the jars folder.


After discussion with @ehrenfeu, I created a small example project that illustrates how packaging multiple scripts into a single jar file is supposed to work:

(@ctrueden if you think it is useful, we can move this project to the imagej org, next to the other example-* projects.)

To create your own project bundling your script files:

  • copy the pom.xml from the linked repository
  • put your scripts into a subfolder of ./src/main/resources/scripts/ (the subfolder name(s) will represent the menu path for each script),
  • run mvn to build the jar file.

Even when keeping single script files in a Fiji installation (i.e. not using the jar file bundling above), I’d recommend to use ./ instead of ./ to collect your script files: it does the same, but the path is more concise.

Reslicing stack along different dimension

That would be wonderful. Please transfer it!

Seconded. The plugins/Scripts folder is: A) a misnomer (scripts are not plugins!) and B) misleading in that bare classes in plugins/Foo/Bar will appear in the Plugins :arrow_forward: Foo :arrow_forward: Bar menu—the Scripts folder is a special case otherwise.