[JAVA] "Hello world" pour ImageJ avec Eclipse

How can we prepare an environment for the development of ImageJ plugins in Java using Eclipse IDE? Here is an answer. The example below was for Windows 10, but the procedures required for macOS is very similar, except that you don't have to set the environmental variables. It has quite a lot of steps, and a bit challenging for someone who is not familiar with Eclipse.

References These two references are almost identical to mine. Yet, the first one is pretty old (last updated in 2010) with a bug, and I still needed to struggle a bit to get it to work. The second one is in Japanese. So I decided to write my own version in English, which really worked for me. I think the example below is equivalent of Method 3 of the reference 1: "Importing the ImageJ source, using ImageJ build.xml, building with ant"

  1. The ImageJ Eclipse Howto

  2. [Créer un plug-in ImageJ avec Eclipse-Preparation ver.2-](http://aki-miya.hatenablog.com/entry/2017/12/29/Eclipse%E3%81%A7ImageJ%E3%81] % AEPlugin% E4% BD% 9C% E6% 88% 90 _-% E4% B8% 8B% E6% BA% 96% E5% 82% 99% E7% B7% A8_ver.2-)

  3. Install JDK 8

  4. Go to the Oracle web siteanddownloadJDK8.
    Image001.png

  5. Accept License Agreement and download JDK (Windows x64 in this case. Choose the one that is for you).
    Image002.png

  6. You'll have downloaded the file jdk-8u181-windows-x64.exe (Windows x64). Double-click the file and install the JDK to your PC.#

  7. Change the Environment Variables for JDK (NOTE: this is only required for Windows. For macOS, jump to step 5)

    1. Type adv in the Windows Search Box next to the Start button. Click View advanced system settings. Then go to Environmental Variables... > User variables for XXXXX
      Image003.pngImage005.png

    2. Find the folder where the JDK binary files are. It should look like: C:\Program Files\Java\jdk1.8.0_181\bin . Copy the address from the Explorer and paste it into a new field by clicking the New button.
      Image004.pngImage006.png

  8. Type cmd in the Windows Search Box next to the Start button. Launch Command Prompt. (for macOS, launch Terminal)

  9. Type javac -version into Command Prompt and press Enter.

  10. If the installation of JDK is successful, you'll see the version of JDK as below:
    Image051.png

  11. Install Eclipse

  12. Go to Eclipse download page https://www.eclipse.org/downloads/ and Click the Download button. Click Download in the next page to start downloading. 
    Image007.png 
    Image008.png

  13. Launch the Eclipse installer, and click Eclipse IDE for Java Developers.
    Image009.png

  14. Choose Installtion folder. With regard to file permission, it is recommended to install Eclipse outside of usual C:\Programs\. click the INSTALL button.
    Image010.png

  15. During installation, you'll be asked about licensing. Click Accept to proceed. 
    Image011.png

  16. Launch Eclipse. 
    Image012.png

  17. Select a directory as workspace. Accept as it is and click Launch. 
    Image013.png

  18. It will look like this: 
    Image014.png

  19. Create a Java project IJ

  20. Create a new Java Project from File > New > Java Project: 
    Image015.png

  21. Type IJ for Project name, and click Next. 
    Image016.png

  22. In the Source tab, make sure that Default output folder is set as IJ/bin. 
    Image017.png

  23. Then click Link additional source:. This will make ImageJ jar files available to this Java project.

    1. Download the latest version of Image from https://imagej.nih.gov/ij/download/src/. Unzip the file in a appropriate folder.

    2. Using Browse button, choose the source folder within the ImageJ folder unzipped. Click Next. 
      Image019.png

    3. In the Inclusion and Exclusion Patterns dialog, click Add for Inclusion patterns.  
      Image052.png

    4. Type IJ_Props.txt or browse to select that file. click OK. 
      Image020.png

    5. Also Add ij/ to Inclusion patterns. Image021.png

    6. Also Add images/, macors/, and plugins/ to Exclusion patterns, and click Finish. 
      Image022.png

  24. In the Libraries tab, click Add External JARs..., and browse to JDK's toolbar.jar file.
    Image018.png

    • In Windows 10, toolbar.jar can be found at C:\Program Files\Java\jdk1.8.0_181\lib\toolbar.jar or somewhere similar.
    • In macOS, it can be found at /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/toolbar.jar .
  25. Create a Java project TESTPlugin_

  26. Create a new Java Project from File > New > Java Project: 
    Image015.png

  27. Set Project name as TESTPlugin_. In order to show the new plugin in ImageJ's pull down menu, the name must end with underscore _. Click Next. 
    Image024.png

  28. In the Source tab, make sure that the Default output folder is set to TESTPlugin_/bin.
    Image025.png

  29. In the Projects tab, click Add and select the IJ, which you've just created. Click Finish.
    Image026.png
    Image027.png

  30. Create TESTPlugin_ class

  31. Add a new class to the project TESTPlugin_ by New > Class
    Image023.png

  32. Set Name to TESTPlugin_ and click Finish.
    Image028.png

  33. Copy the code below and paste it into TESTPlugin_.java. Make sure the name of the .java file and the class name must be identical. Again, you need the underscore _ in order to make this plugin visible in ImageJ's pulldown menu.
    Image029.png

import ij.IJ;
import ij.plugin.PlugIn;
 
public class TESTPlugin_ implements PlugIn {
	public void run(String arg) {
		IJ.error("Hello world!");
	}
}
  1. Create build.xml

  2. Create a new file by File > New > File. Under the project TestPlugin_.
    Image030.png
    Image031.png

  3. Copy and paste the code below to the file build.xml. 
    Image032.png

<project name="TESTPlugin_" default="" basedir=".">
    <description>
        TESTPlugin_ build file
    </description>
  <property name="src" location="src" />
  <property name="build" location="bin" />
  <property name="dist"  location="dist" />
 
	 <property name="pluginsDir"  location="$basedir/../../IJ/plugins/" />
 
  <property name="user.name" value="Patrick Pirrotte" />
<target name="main" depends="compress" description="Main target">
	<echo>
		Building the .jar file.
	</echo>
</target>
 <target name="compress" depends="" description="generate the distribution">
 	<jar jarfile="TESTPlugin_.jar">
 		<fileset dir="." includes="plugins.config" />
		<fileset dir="${build}" includes="**/*.*" />
 		<manifest>
 		 	 	      <attribute name="Built-By" value="${user.name}"/>
 		</manifest>
 	</jar>
    <copy file="TESTPlugin_.jar" toDir="${pluginsDir}" />
  </target>
</project>
  1. Builder configuration

  2. From Package Explorer, right-click on the TESTPlugin_ project and select Properties.
     Image033.png

  3. In the Property dialog, click Builders. 
     Image034.png

  4. In Builders, click New..., and select Ant Builder and click OK. 
     Image035.png

  5. In the Main tab, go to Buildfile: and click Browse Workspace... and select the build.xml in TESTPlugin_ project. 
    Image037.png 
    Image036.png

  6. In the Targets tab, click Set Targets... for both After a "Clean": and Auto Build:, and select main and compress for both of them.
    Image038.png 
    Image053.png 
     Image039.png

  7. Debug

  8. Run > Debug Configurations...  
     Image041.png

  9. Double-click Java application. Set Project to IJ and Main class: to ij.ImageJ (JavaPackageName.ClassName) 
    Image042.png 
     Image044.png

  10. Go to the Source tab, and click Add... 
     Image045.png

  11. Select Java Project and click OK 
     Image046.png

  12. Select the TESTPlugin_ project. This step is crucial if you want to step into your plugin source during the debug phase. 
     Image047.png

  13. Apply the changes and then click Debug. 
     Image048.png

  14. ImageJ should launch and select Plugins > TESTPlugin (it should be visible at this stage).
     Image049.png

  15. You'll see the Hello World message. 
     Image050.png

Contact

Dr Kouichi C. Nakamura [email protected] [email protected]

MRC Brain Network Dynamics Unit, Department of Pharmacology, University of Oxford

Recommended Posts

"Hello world" pour ImageJ avec Eclipse
Hello World avec Eclipse + Spring Boot + Maven
Hello World avec Micronaut
Hello World avec Spring Boot
Bonjour tout le monde avec Spring Boot!
Bonjour tout le monde avec VS Code!
Hello World avec Spring Boot
Hello World avec SpringBoot / Gradle
Bonjour tout le monde! Avec Asakusa Framework!
Spring Boot Hello World dans Eclipse
Jusqu'à "Hello World" avec Spring Boot
Bonjour tout le monde avec Kotlin et JavaFX
Hello World avec Docker et langage C
Bonjour le monde de Java dans Eclipse maintenant
(Intellij) Hello World avec Spring Boot
Hello World avec GlassFish 5.1 + Servlet + JSP
Créez un PDF avec itext7 ~ HelloWorld ~
Hello World avec GWT 2.8.2 et Maven
Développement Java avec Codenvy: Hello World! Run
"Hello, World!" Avec Kotlin + CLI en 5 minutes
Bonjour tout le monde avec Kotlin et Tornado FX
Comment Spring Security fonctionne avec Hello World
(IntelliJ + gradle) Hello World avec Spring Boot
Lire "Hello world"
Java, bonjour le monde!
Java Hello World
Hello World avec JavaFX 11 (OpenJFX) de Liberica JDK 11
Bonjour tout le monde! Avec Spring Boot (Marven + éditeur de texte)
Hello World à une vitesse explosive avec Spring Initializr! !! !!
Exécutez JSP Hello World avec Tomcat sur Docker
[Java] Hello World avec Java 14 x Spring Boot 2.3 x JUnit 5 ~
Afficher un simple Hello World avec SpringBoot + IntelliJ
Facile à afficher Hello World avec Rails + Docker
Hello World (API REST) avec Apache Camel + Spring Boot 2
Apprendre Java (1) - Hello World
Lire System.out.println ("bonjour, monde")
Écrivons Hello World
Hello World en Java
Étudier Java-Partie 1-Hello World
[Java] Procédure de construction de l'environnement pour le développement de struts 1.3 avec Eclipse
Développement de plug-in avec ImageJ
Hello World avec Web Assembly
Hello World (application console) avec Apache Camel + Spring Boot 2
[Java] Un type d'alphabet interdit Avec reliure Bonjour tout le monde! [Reliure]
Créez un CRUD simple avec SpringBoot + JPA + Thymeleaf ① ~ Hello World ~
Créez une application Web Hello World avec Spring Framework + Jetty
[Vue Rails] "Hello Vue!" Affiché avec Vue + Rails
Préparation au développement avec Rails
java bonjour le monde, compilez, exécutez
Les débutants en Java lisent Hello World
Connectez-vous à Oracle avec Eclipse!
Jusqu'à ce que vous exécutiez Hello World of JavaFX avec VSCode + Gradle
Essayez HelloWorld avec la configuration minimale de Heroku Java spring-boot
Comparez Hello, world! Avec Spring Boot avec Java, Kotlin et Groovy
[Eclipse / github] Partageons le projet créé avec eclipse sur github Pour les débutants