Debugging headless macro in Imagej2

imagej
#1

I’m trying to debug a plugin that works in GUI ImageJ, but fails in headless mode. I’ve tried three different methods: running an application with net.imagej.Main; running an application with ij.ImageJ; and using the --debugger mode. Does anyone know the trick to any of these methods?

net.imagej.Main

I’ve managed to set up IntelliJ with the plugin and to get it to run a headless ImageJ2 through net.imagej.Main, but this class doesn’t seem to accept the -macro, -script, or --run keywords in program arguments. It gives me warnings, e.g. [WARNING] Ignoring invalid argument: --run. I haven’t been able to find documentation for what arguments it does accept.

Is there a way to run a macro using the net.imagej.Main class? Is there a documentation page for what arguments it does accept?

ij.ImageJ

I tried using the ‘ij.Main’ class; this lets me run the macro using the keyword arguments, but it won’t run in headless mode. It always opens an IJ1 console and ignores the --ij2 and --headless keywords.

How do you get headless mode to run when calling ij.ImageJ?

--debugger

Finally, I’ve tried using the --debugger mode: setting up IntelliJ to listen to a port, then calling ImageJ.exe through the console. I get a “The syntax of the command is incorrect” when I use the command that Intellij provides.

I’ve used both the “Shared memory” transport method using an address of “8000”
-agentlib:jdwp=transport=dt_shmem,server=n,address=8000,suspend=y,onthrow=<FQ exception class name>,onuncaught=<y/n>

and a “Socket” transport method with no Host = nothing or localhost, and several different ports.
-agentlib:jdwp=transport=dt_socket,server=n,address=MEDICALDEV15.Morgridge.net:8000,suspend=y,onthrow=<FQ exception class name>,onuncaught=<y/n>

Does anyone know what I’m doing wrong with these commands, or is my methodology for the debugger incorrect?

#2

I cant help using the class for the headless.

However for headless using a bare command line as here, the --console argument is necessary to get the output from the macro (including error message).
So you could try to debug the plugin this way.

#3

Thanks @LThomas. That is a good point; it is still possible to debug just using --console and the stack trace. I have found exactly where the error is using that method.

It would still be helpful if anyone knows how to link it to the IDE though; my hope was to use the IDE to interactively debug and figure out what is going on.