Hello World for ImageJ Java Plugin

I wrote a few ImageJ plugins a decade ago, and at that time it was relatively simple. ImageJ only worked with Java or ImageJ Macro language. But ImageJ is like a hybrid of ImageJ1 and ImageJ2, which are completely different internally, and it accepts scripting in BeanShell, Groovy, ImageJ Macro, JavaScript, Lisp (Clojure), MATLAB, Python, R, Ruby, and Scala, half of which I've never heard of.

With that, the way to write and execute the simplest ImageJ Plugin in Java was kind of lost, at least to me. It certainly doesn't exist in the Scripting page.Maybethis is the page, but it's rather difficult to reach and doesn't seem to give you the simplest code example.

I've written an article about "Hello world" for ImageJ with Eclipse", but this is way too complicated for a beginner and me.

So, here I show you how to write the simplest "Hello World" ImageJ Plugin.

  1. Save the Java source code (.java)

1. File > New > Script... will open a new script document in the Script Editor. Image005.png

2. In the Script Editor, select Templates > [by Language] > Java > Imagej 1.x > Skeltons > Bare Plugin. Image006.png

3. You'll see this code. Image007.png

4. Copy and paste the following code to the file.

import ij.plugin.PlugIn;
import ij.IJ;

/**
 * This is a template for a plugin that does not require one image
 * (be it that it does not require any, or that it lets the user
 * choose more than one image in a dialog).
 */
public class Bare_PlugIn implements PlugIn {
	/**
	 * This method gets called by ImageJ / Fiji.
	 *
	 * @param arg can be specified in plugins.config
	 * @see ij.plugin.PlugIn#run(java.lang.String)
	 */
	@Override
	public void run(String arg) {
		IJ.showMessage("Hello World");
	}
}
import ij.IJ;
IJ.showMessage("Hello World");

5. After the edit, it should look like this. Image009.png

6. Save the Bare_Plugin.java to anywhere in your computer by File > Save. Image010.png

  1. Save .jar in the plugins folder 7. Then, export the code as a Bare_Plugin.jar file (Java Archive) in the plugins folder (Fiji.app\plugins) by File > Export as .jar. Image011.png

Image012.png

8. There will be a Java error, but just ignore it. Image013.png

Image014.png

9. Now you can find the Bare_plugin.jar file in the plugins folder. Image015.png

  1. Run the plugin 10. Re-lauch ImageJ/Fiji. Image016.png

11. Go Plugins > Bare Plugin to run the plugin. Image018.png

12. There you go! You can see the Hello World message showing up. Image019.png

Recommended Posts

Hello World for ImageJ Java Plugin
Java, Hello, world!
Java Hello World
"Hello world" for ImageJ with Eclipse
Java Learning (1)-Hello World
Hello World in Java
java hello world, compile, run
Java beginners read Hello World
Hello World on AWS Lambda + Java
Hello World in java in eclipse now
Hello world in Java and Gradle
Creating an Elasticsearch Plugin Series (1) Hello World
Java development with Codenvy: Hello World! Run
Hello World on Mac VS Code Java
Convenient plugin for Eclipse JAVA development: Decompiler
Minimal Java environment construction and Hello World
For JAVA learning (2018-03-16-01)
Read "Hello world"
2017 IDE for Java
Hello Java Lambda
Programming for the first time in my life Java 1st Hello World
Java for statement
Build Java environment and output hello world [Beginner]
[Java] Hello World with Java 14 x Spring Boot 2.3 x JUnit 5 ~
Display "Hello World" in the browser using Java
Display "Hello World" in the browser using Java
Wastefully creative "Hello World" output method list (Java)
[Java] for statement, while statement
[Java] Package for management
[Java] for statement / extended for statement
Read System.out.println ("hello, world")
Let's write Hello World
Hello world in node.js
Countermeasures for Java OutOfMemoryError
NLP for Java (NLP4J) (2)
Studying Java-Part 1-Hello World
(Memo) Java for statement
NLP for Java (NLP4J) (1)
Plugin development with ImageJ
Hello World on WebAssembly
Hello World with Micronaut
[Java] One type of alphabet prohibited With binding Hello, world! [Binding]
Try Hello World using plain Java on a Docker container
Hello World with Spring Boot
Java history in this world
[Gradle] About Java plug-in tasks
Java debug execution [for Java beginners]
[Java] Basic statement for beginners
[Java] Precautions for type conversion
Hello World with Spring Boot!
Hello World with VS Code!
2018 Java Proficiency Test for Newcomers-Basics-
Java thread safe for you
[Java] Summary of for statements
Hello World with Spring Boot
Java for beginners, data hiding
[Java] Tips for writing source
Java installation location for mac
Hello World with SpringBoot / Gradle
Java application for beginners: stream
Java while and for statements