Search code examples
imagej

ImageJ: How to use third-party plugins API?


In Eclipse, I'm using the already packed ij.jar instead of the source code. I added the ij.jar file as an external jar in Eclipse. Every plugin shipped in the original ij.jar works fine after I imported from ij.

Currently, I'm trying to use functions in the third-party plugin StackReg. Does anyone know how I can import the classes inside StackReg? I've tried to add StackReg_.jar as an external jar. However, this does not work.


Solution

  • From quickly looking at the source of StackReg plugin, I see that the classes are in the default package. In java, importing classes from default package to a named package is not possible without using reflection.

    Possible solutions are:

    • Put your classes in the default package. Then you can use the classes in the default package without importing them. Note that using default package is bad practice in java.
    • Use reflection: https://stackoverflow.com/a/561183/1903534
    • Alter the StackReg plugin to not use the default package. But this might not be compatible with its license and your solution will not be compatible with the original jar.