Utilize plugin with only class files

Hello,
So I created my first plugin, using Eclipse as an IDE. To integrate my plugin to ImageJ, I exported the executable jar file from Eclipse to the ImageJ’s plugin folder, as well as the class files. I found that my plugin would only open if the plugins folder contained both the jar file and class files. However, I was told that I should be able to run the plugin with just the class files alone. Does anyone know how that can be achieved? I used this tutorial https://imagej.nih.gov/ij/download/docs/tutorial171.pdf. Here is the beginning of my code which I think is most relevant, as well as the error message I am receiving:

import ij.process.*;
import ij.gui.*;
import ij.plugin.PlugIn;
import java.awt.*;
// other imports not included

public class FCS_3 implements PlugIn {

	    FilePanel filePanel;
	    File[] innerFilePath;

	
	 @Override
	 public void run(String arg){

		SwingUtilities.invokeLater(new Runnable() {
			 @Override
			public void run() {
				JFrame frame = new MainFrame("bimFCS Analysis");
				frame.setSize(620, 450);
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.setVisible(true);
			}
		});
	}
}

class MainFrame extends JFrame {


	private DetailsPanel detailsPanel;
	private DetailsPanel3 detailsPanel3;
	private FilePanel filePanel;

	public MainFrame(String title) {
		super(title);


//more code...

Error Message:

java.lang.NoClassDefFoundError: MainFrame
    at FCS_3.run(FCS_3.java:60)
    at ij.IJ.runUserPlugIn(IJ.java:216)
    at ij.IJ.runPlugIn(IJ.java:180)
    at ij.Executer.runCommand(Executer.java:137)
    at ij.Executer.run(Executer.java:66)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: MainFrame
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more

so it seems the issue starts at my MainFrame class, but I don’t understand why the MainFrame class isn’t found at run time? If I left out any useful information, let me know, any help is appreciated!

You are working with an nested (inner) class if I ignore the wrong number of parentheses in your given example, right?

If compiled you will see in Eclipse your compiled main FCS_3 class and the extra inner classes if you look into your Eclipse bin folder.

Nested (inner) classes are compiled into their own .class file with a name in the form of something like MainFrame$InnerClass.class

I guess you only put the FCS_3 class into the plugins folder.

Pack your multiple classes in a *.jar or create a plugin which doesn’t use a nested class.

1 Like

To avoid the need of manually copying any files (and their possible dependencies) to the corresponding folders inside ImageJ, the recommended way for developing plugins is using Maven. You can get started by simply cloning or downloading the Minimal IJ1 Plugin repository and then importing this project into Eclipse using File > Import: Maven > Existing Maven Projects… Edit the pom.xml file to include dependencies for your plugin and change the name of the main class according to your own needs.

Running the following command will then compile and package a single jar file for your plugin and copy this file as well as all its external dependencies to your ImageJ installation:

mvn -Dimagej.app.directory=/path/to/your/ImageJ.app

Alternatively, you can setup Eclipse to do this whenever you compile your project, see the wiki page about Developing ImageJ in Eclipse.

2 Likes

Ah I see, the nested classes seemed to be the issue. It runs fine with just the class files now. I really appreciate it!

Thank you for the information regarding Maven, this seems like a very handy tool and I will definitely utilize this for the future, thank you very much for the help!