In [1]:
#!groovy
// @ImageJ ij

// The plugin service manages the available plugins (see "Plugins" below).
pluginCount = ij.plugin().getIndex().size()
println("There are " + pluginCount + " plugins available.")

// The log service is used for logging messages.
ij.log().info("Ignoring negative sigma value.")

// The status service is used to report the current status of operations.
// Within a notebook like this, the call does not do anything visible.
ij.status().showStatus("Processing data file 34 of 97...")

// The menu service organizes a menu hierarchy for modules (see "Modules" below).
menuItemCount = ij.menu().getMenu().size()
println("There are " + menuItemCount + " menu items total.")


There are 1602 plugins available.
[INFO] Ignoring negative sigma value.
There are 319 menu items total.
Out[1]:
No Outputs

In [2]:
import org.scijava.plugin.Plugin
import org.scijava.plugin.Parameter
import org.scijava.log.LogService
import org.scijava.command.Command

@Plugin(type = Command.class)
public class MyPlugin implements Command {
 
  // This @Parameter notation is 'asking' the Context
  // for an instance of LogService.
  @Parameter
  private LogService logService
  
  @Parameter
  private String message
 
  @Override
  public void run() {
    // Just use the LogService!
    // There is no need to construct it, since the Context
    // has already provided an appropriate instance.
    logService.info(message)
  }
  
  public void log(String message) {
    // Just use the LogService!
    // There is no need to construct it, since the Context
    // has already provided an appropriate instance.
    logService.info(message);
  }
}

// executing our sample command
ij.command().run(MyPlugin.class, true, "message", "Success!")


Out[2]:
java​.util​.concurrent​.FutureTask​@20a367ec

In [3]:
import org.scijava.plugin.Plugin
import org.scijava.Context;
import org.scijava.plugin.Parameter
import org.scijava.command.Command

@Plugin(type = Command.class)
public class MyService implements Command {
 
  // This service will manually create plugin instances.
  // So, we need a reference to our containing Context,
  // then we can use it to inject our plugins.
  @Parameter
  private Context context
  
  @Override
  public void run() {
    // Manually create a plugin instance.
    // It is not connected to a Context yet
    MyPlugin plugin = new MyPlugin();
 
    // Inject the plugin instance with our Context.
    context.inject(plugin);
 
    // Now that our plugin is injected, we can use
    // it with the knowledge that its parameters
    // have been populated.
    plugin.log("Success!");
  }
}

// executing our sample command
ij.command().run(MyService.class, true)


Out[3]:
java​.util​.concurrent​.FutureTask​@c753f55

In [4]:
// Create a SciJava gateway.
import org.scijava.SciJava
sj = new SciJava()

// Now bask in the convenience!

println("Plugin count: " + sj.plugin().getPlugins().size())
println("Module count: " + sj.module().getModules().size())

import org.scijava.service.Service
println("Service count: " + sj.plugin().getPluginsOfType(Service.class).size())

println("SciJava version: " + sj.getVersion())
println("Where is SciJava? " + sj.getApp().getLocation())


Plugin count: 1604
Module count: 1105
Service count: 97
SciJava version: 2.64.0
Where is SciJava? file:/home/hadim/local/Fiji.app/jars/scijava-common-2.64.0.jar
Out[4]:
No Outputs