I want to edit in the core of Imagej1 but I am not able

I am using Maven and my code does work but currently I would like to edit in the files of ImageJ1 which I am not able to do as the files are read only.

I couldn’t find any version of ImageJ2 that provides the .java files for the whole project. Is there a way that I can edit the source code or am I only allowed to add plugins?

I tried to exclude ij library from ImageJ2 in maven and add a local repository of the same version but I am getting errors.

Maven excluding ij package

<dependencies>
         <dependency>
             <groupId>net.imagej</groupId>
             <artifactId>imagej</artifactId>
             <exclusions>
                 <exclusion>
                     <groupId>net.imagej</groupId>
                     <artifactId>ij</artifactId>
                 </exclusion>
             </exclusions>
         </dependency>
</dependencies>

errors shown

java.lang.IllegalArgumentException: Cannot handle replace call to show in ij.gui.StackWindow's public <init>(ij.ImagePlus imp, ij.gui.ImageCanvas ic)
	at net.imagej.patcher.CodeHacker.replaceCallInMethod(CodeHacker.java:725)
	at net.imagej.patcher.CodeHacker.replaceCallInMethod(CodeHacker.java:650)
	at net.imagej.patcher.LegacyInjector.inject(LegacyInjector.java:320)
	at net.imagej.patcher.LegacyInjector.injectHooks(LegacyInjector.java:109)
	at net.imagej.patcher.LegacyEnvironment.initialize(LegacyEnvironment.java:101)
	at net.imagej.patcher.LegacyEnvironment.applyPatches(LegacyEnvironment.java:495)
	at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:397)
	at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:376)
	at net.imagej.legacy.LegacyService.<clinit>(LegacyService.java:130)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.lang.Class.newInstance(Class.java:442)
	at org.scijava.service.ServiceHelper.createServiceRecursively(ServiceHelper.java:302)
	at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:269)
	at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:231)
	at org.scijava.service.ServiceHelper.createServiceRecursively(ServiceHelper.java:340)
	at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:269)
	at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:231)
	at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:194)
	at org.scijava.service.ServiceHelper.loadServices(ServiceHelper.java:166)
	at org.scijava.Context.<init>(Context.java:267)
	at org.scijava.Context.<init>(Context.java:224)
	at org.scijava.Context.<init>(Context.java:163)
	at org.scijava.Context.<init>(Context.java:149)
	at net.imagej.ImageJ.<init>(ImageJ.java:79)
	at net.imagej.Main.launch(Main.java:61)
	at Testing.main(Testing.java:640)
Caused by: java.lang.RuntimeException: cannot find ij.macro: ij.Macro found in ij/macro.class
	at javassist.CtClassType.getClassFile2(CtClassType.java:196)
	at javassist.CtClassType.makeFieldCache(CtClassType.java:867)
	at javassist.CtClassType.getMembers(CtClassType.java:858)
	at javassist.CtClassType.getDeclaredField2(CtClassType.java:992)
	at javassist.CtClassType.getField2(CtClassType.java:946)
	at javassist.CtClassType.getField(CtClassType.java:927)
	at javassist.CtClass.getField(CtClass.java:819)
	at javassist.compiler.MemberResolver.lookupFieldByJvmName2(MemberResolver.java:283)
	at javassist.compiler.TypeChecker.fieldAccess2(TypeChecker.java:913)
	at javassist.compiler.TypeChecker.fieldAccess(TypeChecker.java:870)
	at javassist.compiler.TypeChecker.atFieldRead(TypeChecker.java:803)
	at javassist.compiler.TypeChecker.atExpr(TypeChecker.java:578)
	at javassist.compiler.ast.Expr.accept(Expr.java:68)
	at javassist.compiler.TypeChecker.fieldAccess(TypeChecker.java:860)
	at javassist.compiler.TypeChecker.atFieldRead(TypeChecker.java:803)
	at javassist.compiler.TypeChecker.atExpr(TypeChecker.java:578)
	at javassist.compiler.ast.Expr.accept(Expr.java:68)
	at javassist.compiler.TypeChecker.booleanExpr(TypeChecker.java:523)
	at javassist.compiler.TypeChecker.atExpr(TypeChecker.java:592)
	at javassist.compiler.ast.Expr.accept(Expr.java:68)
	at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:242)
	at javassist.compiler.CodeGen.compileBooleanExpr(CodeGen.java:236)
	at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:384)
	at javassist.compiler.CodeGen.atStmnt(CodeGen.java:355)
	at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
	at javassist.compiler.Javac.compileStmnt(Javac.java:569)
	at javassist.expr.MethodCall.replace(MethodCall.java:235)
	at net.imagej.patcher.CodeHacker$7.edit(CodeHacker.java:686)
	at javassist.expr.ExprEditor.loopBody(ExprEditor.java:192)
	at javassist.expr.ExprEditor.doit(ExprEditor.java:91)
	at javassist.CtBehavior.instrument(CtBehavior.java:712)
	at net.imagej.patcher.CodeHacker$EagerExprEditor.instrument(CodeHacker.java:1278)
	at net.imagej.patcher.CodeHacker.replaceCallInMethod(CodeHacker.java:670)
	... 28 more
Exception in thread "main" java.lang.IllegalArgumentException: Invalid service: net.imagej.legacy.LegacyConsoleService
	at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:280)
	at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:231)
	at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:194)
	at org.scijava.service.ServiceHelper.loadServices(ServiceHelper.java:166)
	at org.scijava.Context.<init>(Context.java:267)
	at org.scijava.Context.<init>(Context.java:224)
	at org.scijava.Context.<init>(Context.java:163)
	at org.scijava.Context.<init>(Context.java:149)
	at net.imagej.ImageJ.<init>(ImageJ.java:79)
	at net.imagej.Main.launch(Main.java:61)
	at Testing.main(Testing.java:640)
Caused by: java.lang.IllegalArgumentException: Invalid service: net.imagej.legacy.LegacyService
	at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:280)
	at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:231)
	at org.scijava.service.ServiceHelper.createServiceRecursively(ServiceHelper.java:340)
	at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:269)
	... 10 more
Caused by: java.lang.VerifyError: Expecting a stack map frame
Exception Details:
  Location:
    ij/IJ.getClassLoader()Ljava/lang/ClassLoader; @176: nop
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0x0000000: b20a 5301 a600 24b8 0057 b60a 56b3 0a53
    0x0000010: b20a 5304 b80a 5a4b 2a01 a500 0eb8 0057
    0x0000020: 2ab6 0a14 2ab3 0a53 b20a 53b0 0000 00a7
    0x0000030: fffd 0000 0000 00a7 fffb 0000 0000 0000
    0x0000040: 0000 0000 0000 0000 0000 0000 a7ff ee00
    0x0000050: 0000 0000 0000 a7ff f9a7 0000 0000 a7ff
    0x0000060: fe00 0000 00a7 fffc 0000 0000 0000 00a7
    0x0000070: fff9 0000 0000 0000 0000 0000 0000 0000
    0x0000080: 0000 0000 a7ff ee00 0000 0000 0000 0000
    0x0000090: 0000 0000 0000 0000 0000 0000 0000 0000
    0x00000a0: 0000 0000 0000 0000 0000 0000 00a7 ffda
    0x00000b0: 00bf 00a7 ffff 0000 0000 a7ff fc00 0000
    0x00000c0: a7ff fd00 0000 0000 0000 0000 0000 00a7
    0x00000d0: fff4 0000 0000 0000 0000 a7ff f800 a7ff
    0x00000e0: ff                                     
  Stackmap Table:
    same_frame(@40)
    same_frame(@44)
    same_frame(@50)
    same_frame(@58)
    same_frame(@79)
    same_frame(@89)
    same_frame(@92)
    same_frame(@97)
    same_frame(@104)
    same_frame(@114)
    same_frame(@135)
    same_frame(@178)
    same_frame(@182)
    same_frame(@189)
    same_frame(@195)
    same_frame(@210)
    same_frame(@221)

	at java.lang.Class.getDeclaredFields0(Native Method)
	at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
	at java.lang.Class.getField0(Class.java:2975)
	at java.lang.Class.getField(Class.java:1701)
	at net.imagej.patcher.LegacyEnvironment.initialize(LegacyEnvironment.java:105)
	at net.imagej.patcher.LegacyEnvironment.applyPatches(LegacyEnvironment.java:495)
	at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:397)
	at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:376)
	at net.imagej.legacy.LegacyService.<clinit>(LegacyService.java:130)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.lang.Class.newInstance(Class.java:442)
	at org.scijava.service.ServiceHelper.createServiceRecursively(ServiceHelper.java:302)
	at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:269)
	... 13 more
Disconnected from the target VM, address: '127.0.0.1:49559', transport: 'socket'

Process finished with exit code 1

Hi @Mourka,

Check out this wiki page and this git repo:

It’s not super clear at the moment where you got the imagej1 source code, or what you did to get the error above. Definitely post back with some more details if you’re still having trouble after reading that wiki page.

Good luck
John

2 Likes

@bogovicj Thank you for your reply and sorry if my question was not clear. I also read the wiki and I know I can have an ij.jar out of ImageJA. But my question was about how to replace an already existing legacy ImageJ1 library by the edited one (ImageJA or any version of ant built) in ImageJ2 project. As the original legacy is read only files.

I just found a solution, I created a .jar output file for the imageJ1 ant project with version that matches the library I have in ImageJ2 . Then I added this .jar file as a library into my full ImageJ2 project.

I would try the same with ImageJA, thanks again for your answer.

1 Like

Hi @Mourka,

Glad you figured out something, but we’re happy to continue helping if needed…

Are you using an IDE? What I usually do is to clone/fork the project I want to edit, and change the artifactId to something new, say imagej-mourka.

Then you can say that your imagej2 project depends on your newly renamed imagej1 project. Eclipse and IntelliJ both will notice that you have a project under that name, and will point to it directly, saving you the work of having to build a jar whenever you make changes to the imagej1 project

Just some ideas,
John

2 Likes

@bogovicj yes I am using IDE intelliJ.

So far I tried to use ImageJA which is having the latest version ImageJ1.52q while the project on different trials are using different versions of ImageJ1 and so I can see many exceptions from the patcher but it does work when I run. To avoid the exceptions, I am using the ant build of ImageJ1 to match the version that was used in the whole project. While editing in the ant build, I can’t see my errors as it accepts whatever I write but still I can manage with that just for trials.

I think I will give it a try with git as you said. That was a very good advise.

@Mourka,

If you’re interested in developing with imagej, I would highly recommend learning about maven. It’s like ant, but alot nicer in my opinion.

With git and maven, building imagej(1) is as easy as:

git clone git@github.com:imagej/ImageJA.git
cd ImageJA
mvn
2 Likes

I did as you said just now. I think I got what you mean, so I edit in the ImageJA project and the generated jar file from maven is already used in the whole project. Correct it works now and I can see all the errors I do here and there. The new jar is automatically grabbed with a run so no need to re-build. Maven is better yes as with ant I am having hard time tracking my errors.

1 Like