Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageJ ij = new ImageJ() fails #24

Closed
reckbo opened this issue Dec 2, 2015 · 6 comments
Closed

ImageJ ij = new ImageJ() fails #24

reckbo opened this issue Dec 2, 2015 · 6 comments

Comments

@reckbo
Copy link

reckbo commented Dec 2, 2015

Hi,

I've installed ImageJ as a library for my project using the gradle line

compile 'net.imagej:imagej:2.0.0-rc-9-SNAPSHOT'

which seemed to download every ImageJ package known to man. I'm now trying to get the simplest example working, i.e.

import net.imagej.ImageJ;
...
ImageJ ij = new ImageJ();

but I get a long stack trace of errors which ends with 'error in opening zip file' (see below). Any idea of what's going on?

thanks!
Ryan

Full stack trace
java.lang.IllegalArgumentException: Cannot handle replace call to list in ij.Menus's public static synchronized java.lang.String[] getPlugins()
    at net.imagej.patcher.CodeHacker.replaceCallInMethod(CodeHacker.java:724)
    at net.imagej.patcher.CodeHacker.replaceCallInMethod(CodeHacker.java:649)
    at net.imagej.patcher.LegacyExtensions.addExtraPlugins(LegacyExtensions.java:475)
    at net.imagej.patcher.LegacyExtensions.injectHooks(LegacyExtensions.java:175)
    at net.imagej.patcher.LegacyInjector.inject(LegacyInjector.java:286)
    at net.imagej.patcher.LegacyInjector.injectHooks(LegacyInjector.java:87)
    at net.imagej.patcher.LegacyEnvironment.initialize(LegacyEnvironment.java:101)
    at net.imagej.patcher.LegacyEnvironment.applyPatches(LegacyEnvironment.java:496)
    at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:365)
    at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:344)
    at net.imagej.legacy.DefaultLegacyService.<clinit>(DefaultLegacyService.java:113)
    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:422)
    at java.lang.Class.newInstance(Class.java:442)
    at org.scijava.service.ServiceHelper.createServiceRecursively(ServiceHelper.java:301)
    at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:268)
    at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:230)
    at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:193)
    at org.scijava.service.ServiceHelper.loadServices(ServiceHelper.java:165)
    at org.scijava.Context.<init>(Context.java:234)
    at org.scijava.Context.<init>(Context.java:195)
    at org.scijava.Context.<init>(Context.java:138)
    at org.scijava.Context.<init>(Context.java:98)
    at org.scijava.Context.<init>(Context.java:86)
    at net.imagej.ImageJ.<init>(ImageJ.java:82)
    at apps.RatMatlab.main(RatMatlab.java:106)
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18 at 168
    at javassist.CtClassType.getClassFile2(CtClassType.java:204)
    at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:98)
    at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:84)
    at javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:711)
    at javassist.compiler.TypeChecker.atCallExpr(TypeChecker.java:688)
    at javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:157)
    at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
    at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:242)
    at javassist.compiler.CodeGen.atStmnt(CodeGen.java:330)
    at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
    at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:391)
    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:685)
    at javassist.expr.ExprEditor.loopBody(ExprEditor.java:192)
    at javassist.expr.ExprEditor.doit(ExprEditor.java:91)
    at javassist.CtBehavior.instrument(CtBehavior.java:679)
    at net.imagej.patcher.CodeHacker$EagerExprEditor.instrument(CodeHacker.java:1278)
    at net.imagej.patcher.CodeHacker.replaceCallInMethod(CodeHacker.java:669)
    ... 27 more
Caused by: java.io.IOException: invalid constant type: 18 at 168
    at javassist.bytecode.ConstPool.readOne(ConstPool.java:1044)
    at javassist.bytecode.ConstPool.read(ConstPool.java:984)
    at javassist.bytecode.ConstPool.<init>(ConstPool.java:125)
    at javassist.bytecode.ClassFile.read(ClassFile.java:770)
    at javassist.bytecode.ClassFile.<init>(ClassFile.java:114)
    at javassist.CtClassType.getClassFile2(CtClassType.java:191)
    ... 47 more
java.lang.IllegalArgumentException: Cannot handle app name in ij.ImageJ's public <init>(java.applet.Applet applet, int mode)
    at net.imagej.patcher.CodeHacker.replaceAppNameInCall(CodeHacker.java:445)
    at net.imagej.patcher.LegacyExtensions.insertAppNameHooks(LegacyExtensions.java:404)
    at net.imagej.patcher.LegacyExtensions.injectHooks(LegacyExtensions.java:290)
    at net.imagej.patcher.LegacyInjector.inject(LegacyInjector.java:286)
    at net.imagej.patcher.LegacyInjector.injectHooks(LegacyInjector.java:87)
    at net.imagej.patcher.LegacyEnvironment.initialize(LegacyEnvironment.java:101)
    at net.imagej.patcher.LegacyEnvironment.applyPatches(LegacyEnvironment.java:496)
    at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:365)
    at net.imagej.patcher.LegacyInjector.preinit(LegacyInjector.java:344)
    at net.imagej.legacy.DefaultLegacyService.<clinit>(DefaultLegacyService.java:113)
    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:422)
    at java.lang.Class.newInstance(Class.java:442)
    at org.scijava.service.ServiceHelper.createServiceRecursively(ServiceHelper.java:301)
    at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:268)
    at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:230)
    at org.scijava.service.ServiceHelper.loadService(ServiceHelper.java:193)
    at org.scijava.service.ServiceHelper.loadServices(ServiceHelper.java:165)
    at org.scijava.Context.<init>(Context.java:234)
    at org.scijava.Context.<init>(Context.java:195)
    at org.scijava.Context.<init>(Context.java:138)
    at org.scijava.Context.<init>(Context.java:98)
    at org.scijava.Context.<init>(Context.java:86)
    at net.imagej.ImageJ.<init>(ImageJ.java:82)
    at apps.RatMatlab.main(RatMatlab.java:106)
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18 at 1
    at javassist.CtClassType.getClassFile2(CtClassType.java:204)
    at javassist.CtClassType.subtypeOf(CtClassType.java:304)
    at javassist.CtClassType.subtypeOf(CtClassType.java:319)
    at javassist.compiler.MemberResolver.compareSignature(MemberResolver.java:235)
    at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:107)
    at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:84)
    at javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:711)
    at javassist.compiler.TypeChecker.atCallExpr(TypeChecker.java:688)
    at javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:157)
    at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
    at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:242)
    at javassist.compiler.CodeGen.atStmnt(CodeGen.java:330)
    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$4.edit(CodeHacker.java:426)
    at net.imagej.patcher.CodeHacker$4.edit(CodeHacker.java:440)
    at javassist.expr.ExprEditor.loopBody(ExprEditor.java:220)
    at javassist.expr.ExprEditor.doit(ExprEditor.java:91)
    at javassist.CtBehavior.instrument(CtBehavior.java:679)
    at net.imagej.patcher.CodeHacker$EagerExprEditor.instrument(CodeHacker.java:1278)
    at net.imagej.patcher.CodeHacker.replaceAppNameInCall(CodeHacker.java:401)
    ... 26 more
Caused by: java.io.IOException: invalid constant type: 18 at 1
    at javassist.bytecode.ConstPool.readOne(ConstPool.java:1044)
    at javassist.bytecode.ConstPool.read(ConstPool.java:984)
    at javassist.bytecode.ConstPool.<init>(ConstPool.java:125)
    at javassist.bytecode.ClassFile.read(ClassFile.java:770)
    at javassist.bytecode.ClassFile.<init>(ClassFile.java:114)
    at javassist.CtClassType.getClassFile2(CtClassType.java:191)
    ... 47 more
/Users/ryan/.gradle/caches/modules-2/files-2.1/com.github.fommil.netlib/all/1.1.1/725430bbcafc5384699fcc73c106502870b24d3e/all-1.1.1.pom: java.util.zip.ZipException: error in opening zip file
/Users/ryan/.gradle/caches/modules-2/files-2.1/com.github.fommil.netlib/all/1.1.1/725430bbcafc5384699fcc73c106502870b24d3e/all-1.1.1.pom: java.util.zip.ZipException: error in opening zip file
@hinerm
Copy link
Member

hinerm commented Dec 2, 2015

'net.imagej:imagej:2.0.0-rc-9-SNAPSHOT'

First off, depending on a SNAPSHOT is not advised because you are not guaranteed to get consistent behavior back.

In this case, rc-9 is also extremely old and probably filled with problems. You can find the latest release version on GitHub and maven.

But in general, the safest thing to do is to inherit dependency management from a release version of the bill of materials we provide, typically by using it as a parent pom or scope:importing it, so that you don't need to specify any other component versions manually. Off-hand I'm not sure how this works in gradle.

which seemed to download every ImageJ package known to man

ImageJ 1.x was designed as a single java project. ImageJ2 is highly modular and extensible. net.imagej:imagej is simply the aggregator for all these components, bundling them together to make a cohesive distribution.

If you have further questions about any of this let me know. Also for general development questions/discussions you may be interested in the ImageJ forum.. I think the community would benefit from the perspective and experiences of a developer who uses gradle.

@ctrueden
Copy link
Member

ctrueden commented Dec 2, 2015

In addition to @hinerm's comments, a couple other notes:

java.io.IOException: invalid constant type: 18 at 1

This means you are using a too-old version of Javassist (one of the project's dependencies) with Java 8. This is probably because you are using an old version of net.imagej:imagej. The problem was fixed a few months ago by upgrading to a newer Javassist—try using the latest version of ImageJ.

java.util.zip.ZipException: error in opening zip file

This often means your build system had problems downloading a JAR file. Easiest solution is to delete the relevant folder from your Gradle/Maven cache, and build again to redownload. However, in this case, the error is about a POM file, which should not be getting treated as a ZIP in the first place. So that is odd. But it may also be a red herring, unrelated to your specific woes here.

@reckbo
Copy link
Author

reckbo commented Dec 7, 2015

Thanks for your help guys -- unfortunately upgrading to the latest release version ('net.imagej:imagej:2.0.0-rc-43') didn't help, although it did vanquish the zip file error.

I took @hinerm's suggestion and added the imagej bom to my gradle build, using version 3.1:

mavenBom 'net.imagej:bom-imagej:3.1'

The problem now is that it fails to find some dependencies (you can see the error below). I've tried these three different maven urls (in addition to maven central):

 url "http://maven.imagej.net/content/groups/hosted/"
 url "http://maven.imagej.net/content/groups/public/"
 url "http://maven.imagej.net/content/repositories/thirdparty/"

The first one worked when I was not using the bom and just importing imagej-20.0.0-rc-43. Should
I be using a different url?

I should mention that my end goal is to use the dilation, erosion, and 3d distance transform
ops in my application, but I probably still need to include the whole imagej framework right?

Thanks for any help!
Ryan


FAILURE: Build failed with an exception.

@hinerm
Copy link
Member

hinerm commented Dec 7, 2015

mavenBom 'net.imagej:bom-imagej:3.1'

Whooops... mis-communication here 😄 the pom-imagej project _is_ the bill of materials.

bom-imagej is an unfortunate historical artifact from when we were experimenting with different pom/bom configurations.

if you use:

mavenBom 'net.imagej:pom-imagej:14.1.0'

and remove any other ImageJ version specification, does it work better?

@reckbo
Copy link
Author

reckbo commented Dec 8, 2015

It works, you are my hero.

To help anyone else using gradle I've listed the relevant lines in my build.gradle below.


buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:0.5.4.RELEASE"
    }
}
apply plugin: "io.spring.dependency-management"

repositories {
    jcenter()
    maven {
          url "http://maven.imagej.net/content/groups/public/"
    }
}
dependencyManagement {
    imports {
        mavenBom 'net.imagej:pom-imagej:14.1.0'
    }
}

dependencies {
    compile 'net.imagej:imagej'
}

@hinerm
Copy link
Member

hinerm commented Dec 8, 2015

To help anyone else using gradle I've listed the relevant lines in my build.gradle below.

Awesome! It's great to hear that it worked for you. Thanks for your persistence 😄

We try to collect all our documentation on the ImageJ wiki - so I started a gradle page in case you run into further pitfalls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants