Build Plugins in Netbeans

Hi,

I’m reaching out because I’ve been working on this for days now but to no avail.

I started by pulling this version of ImageJ down into my NetBeans using Git > Clone: git://github.com/imagej/imagej

Once downloaded, there is a directory called “Plugins” with a readme that says “Plugins go here”, yet no matter what I do to get plugins i have built in there, they just won’t work. I’ve even tried creating a simple hello world one and I can’t get it to appear in the ImageJ plugins menu.

I am reading online things about updating the POM.xml file, but I am new to this so am so confused as to where to start.

Currently, I’ve built a plugin which is spread across 4 classes (files) and I just want it to appear in my NetBeans ImageJ, because I have managed to successfully do this with my normal installation (which I think from what I’m reading online is ImageJ 1).

Please help!

Ryan

Hello Ryan,

To start developing plugins for ImageJ, you don’t need to clone imagej. You can simply start a new Maven project, which declares the following in the POM file:

<parent>
  <groupId>net.imagej</groupId>
  <artifactId>pom-imagej</artifactId>
  <version>15.8.0</version>
  <relativePath />
</parent>

<repositories>
  <repository>
  <id>imagej.public</id>
  <url>http://maven.imagej.net/content/groups/public</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>net.imagej</groupId>
    <artifactId>imagej</artifactId>
  </dependency>
</dependencies>

I.e. you declare that your plugin project uses ImageJ as its parent, you tell where the parent pom can be found, and also declare a dependency on the imagej artefact.

Your plugin doesn’t have to go into the plugins folder. ImageJ discovers available plugins automatically base on the @Plugin annotation. Your class should look like:

@Plugin(type = Command.class, menuPath = "Plugins>My plugin")
public class MyPlugin implements Command {
  @Override
  public void run() {
    // This is where the magic of your plugin happens
  }
}

Then you can launch ImageJ and run your plugin as following:

public static void main(final String... args) {
  // Launch ImageJ as usual.
  final ImageJ ij = net.imagej.Main.launch(args);

  // Launch our "Hello World" command right away.
  ij.command().run(MyPlugin.class, true);
}

Best Regards,
Richard Domander

P.S. For more info have a look at:
https://github.com/imagej/imagej-tutorials/blob/master/simple-commands/pom.xml
https://github.com/imagej/imagej-tutorials/blob/master/simple-commands/src/main/java/HelloWorld.java

5 Likes

Thank you so much!

I stumbled across this link and it made things a little clearer: https://github.com/imagej/minimal-ij1-plugin/

But your answer is fantastic and made it even more clear.

Thanks,

Ryan

4 Likes