pyimagej icon indicating copy to clipboard operation
pyimagej copied to clipboard

Plugins in the plugin folder cannot be used if they are just .class files.

Open odinsbane opened this issue 1 year ago • 4 comments

Some plugins are used by just putting a class file in the plugins folder. These plugins do not load properly in pyimagej.

To reproduce this, take an example plugin and compile it to a class file and place it in the fiji plugins folder.

import ij.plugin.PlugIn;

public class Example_Plugin implements PlugIn {
    @Override
    public void run(String s) {
        System.out.println("That's the one");
    }
}

Starting fiji, the Example Plugin will be available in the menu and running it should produce the desired output.

Starting pyimagej.

import imagej
ij = imagej.init("Fiji.app", mode='interactive')
ij.ui().showUI()

Note the "Fiji.app" is the path to the Fiji that has the plugin installed. This should display the UI with Example Plugin in the menu. Trying to run it will cause a class not found exception.

odinsbane avatar Aug 19 '24 10:08 odinsbane

One work around is the put the class file into a jar.

jar cf Example_Plugin.jar Example_Plugin.class

Restarting pyimagej the plugin should work fine.

odinsbane avatar Aug 19 '24 10:08 odinsbane

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/issue-with-loading-local-plugins-with-pyimagej/100279/9

imagesc-bot avatar Aug 19 '24 10:08 imagesc-bot

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/adjustable-watershed-plugin-in-pyimagej/100563/3

imagesc-bot avatar Aug 19 '24 10:08 imagesc-bot

See also this Zulip topic, where I describe some findings related to this issue.

ctrueden avatar Aug 19 '24 15:08 ctrueden

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/fiji-latest-java-21-bundles-ready-for-community-testing/112417/57

imagesc-bot avatar Jun 06 '25 21:06 imagesc-bot

I opened https://github.com/imagej/pyimagej/issues/334 which I then closed as duplicate of this issue, but wanted to mention that I did find a particular line (addLegacy = false) which when I removed, allowed me to load .class plugins. But I wanted to look more into this flag to find what the proper fix is

hinerm avatar Aug 05 '25 15:08 hinerm

When I specify an imagej installation I can get .class files to load if I include a jars.append( ij_dir + "/plugins") Then plugins gets added to the classpath and .class files get loaded. This is similar to the jaunch solution where a folder needs to be added to the fiji.toml.

I added the line here https://github.com/imagej/pyimagej/blob/74d7d2210201d3523d208a2b5793e08e0a92c4aa/src/imagej/init.py#L1675

odinsbane avatar Aug 06 '25 10:08 odinsbane