Build a ImageJ/Micromanager plugin with IntelliJ

I am trying to develop a plugin for Micromanager 2.0, which uses ImageJ as the base, and I would like to use the IntelliJ IDE as I am familiar with pycharm.

However, I am having problems building the plugin jar using IntelliJ. When I build the jar, it does not contain the JSON folder holding the org.scijava.plugin.Plugin class. This prevents the plugin from being loaded into ImageJ/Micromanager; i.e., I start up ImageJ.exe and it will not show up in the Micromanager plugins list. I can circumvent this by starting Micromanager from IntelliJ using the correct run configuration, but the jar itself is still in the wrong format.

I’ve tested building the same plugin using Netbeans and the jar is built correctly, so there’s no problem with the code. I can run ImageJ/Micromanager from Netbeans or directly as an application and the plugin shows up for both.

Does anyone know how to build the jar correctly in IntelliJ?

Hi @mpinkert,

would you mind sharing a minimal code example with us? It sounds a bit like you want to build a shaded jar, but it’s hard to guess without seeing code.

Cheers,
Robert

Hi @haesleinhuepf,

What part of the code would you like to see? I’ve attached the main class declaration below but I’m not sure what else would help. I believe that the code is working correctly because it compiles fine in Netbeans; it’s the IntelliJ build settings that I am having trouble with.

package org.micromanager.smartgrid;

import org.micromanager.smartgrid.*;

import org.micromanager.MenuPlugin;
import org.micromanager.Studio;
import org.scijava.plugin.Plugin;
import org.scijava.plugin.SciJavaPlugin;

@Plugin(type = MenuPlugin.class)
public class SmartGrid implements SciJavaPlugin, MenuPlugin {
   private Studio studio_;
   private SmartGridFrame frame_;

   /**
    * This method receives the Studio object, which is the gateway to the
    * Micro-Manager API. You should retain a reference to this object for the
    * lifetime of your plugin. This method should not do anything except for
    * store that reference, as Micro-Manager is still busy starting up at the
    * time that this is called.
    */
   @Override
   public void setContext(Studio studio) {
      studio_ = studio;
   }

   /**
    * This method is called when your plugin is selected from the Plugins menu.
    * Typically at this time you should show a GUI (graphical user interface)
    * for your plugin.
    */
   @Override
   public void onPluginSelected() {
      if (frame_ == null) {
         // We have never before shown our GUI, so now we need to create it.
         frame_ = new SmartGridFrame(studio_);
      }
        frame_.setVisible(true);
   }

   /**
    * This string is the sub-menu that the plugin will be displayed in, in the
    * Plugins menu.
    */
   @Override
   public String getSubMenu() {
      return "Developer Tools";
   }

   /**
    * The name of the plugin in the Plugins menu.
    */
   @Override
   public String getName() {
      return "Smart Grid";
   }

   @Override
   public String getHelpText() {
      return "Help text that is displayed in certain contexts to tell the user what the plugin does.";
   }

   @Override
   public String getVersion() {
      return "2.0";
   }

   @Override
   public String getCopyright() {
      return "University of California, 2012-2015";
   }
}

And the corresponding SmartFrameGrid

package org.micromanager.smartgrid;

import org.micromanager.internal.utils.MMDialog;
import org.micromanager.Studio;


public class SmartGridFrame extends MMDialog {
    private Studio studio_;

    public SmartGridFrame(Studio studio){
        studio_ = studio;
    }
}

I would have expected a project folder with a pom file… But you are using the build-system from netbeans apparently? How do Netbeans project files look like? I mean, where might it be defined what goes into the Jar and what not?

Netbeans seems to use a build.xml that links to a subfolder with build-impl.xml and project.properties.

The only other hint I see is that the Netbeans manifest includes the line X-COMMENT: Main-Class will be added automatically by build. The IntelliJ manifest has the line iJ.ImageJ instead.

Unfortunately, I don’t know enough about Netbeans and don’t know what’s in the build-impl.xml. However, the OpenSPIM people use maven projects to deploy to micromanager. You find a description for the procedure here: https://github.com/openspim/SPIMAcquisition/tree/mm2#installing-into-a-micro-manager-directory-instead-of-fiji

2 Likes

I’m not entirely sure how, but the issue seems to have been resolved.

I think that my issue was that I didn’t have a properly generated Manifest file. I made a new manifest while playing around with IntelliJ, which includes the line Main-Class: ij.ImageJ. The project build now creates the jar with org.scijava.plugin.Plugin and the plugin is visible in the .exe.

Edit: Thanks for the link @haesleinhuepf . I’m very new to Java, so this has all made it clear that there’s a lot more to do with building/maven/ant that I need to be aware of.

3 Likes

The framework of the software is ivy. The IDEA plugin ‘ivyIDEA’ should be install. Then,the project can be opened correctly by IDEA