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

Use of OpenImaj in Webservice - Logger issue #124

Open
nusynergi opened this Issue Mar 28, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@nusynergi
Copy link

nusynergi commented Mar 28, 2017

I have built functionality using openImaj in IntelliJ. It works well using the various processes I need. I now need to expose it in a webservice. To do this I am trying to use the Play framework.

I have a basic sample webservice working based upon this tutorial. https://marianafranco.github.io/2014/07/28/rest-play/ and am using IntelliJ to work with it. It runs fine out of the box.

I have added the JAR from the OpenImaj application I built. Test-1.0-SNAPSHOT-jar-with-dependencies.jar . IntelliJ indexes the project and all the dependencies seem to resolve OK (though I did initially have issues with this). I also get no issues when I build the project.

However the when I actually look to run, I get an error complaining about lack of a method : ch.qos.logback.classic.LoggerContext.getFrameworkPackages()

java.lang.NoSuchMethodError: ch.qos.logback.classic.LoggerContext.getFrameworkPackages()Ljava/util/List; at play.api.libs.logback.LogbackLoggerConfigurator.configure(LogbackLoggerConfigurator.scala:87) at play.api.libs.logback.LogbackLoggerConfigurator.init(LogbackLoggerConfigurator.scala:26) at play.core.server.DevServerStart$$anonfun$mainDev$1.apply(DevServerStart.scala:94) at play.core.server.DevServerStart$$anonfun$mainDev$1.apply(DevServerStart.scala:65) at play.utils.Threads$.withContextClassLoader(Threads.scala:21) at play.core.server.DevServerStart$.mainDev(DevServerStart.scala:64) at play.core.server.DevServerStart$.mainDevHttpMode(DevServerStart.scala:54) at play.core.server.DevServerStart.mainDevHttpMode(DevServerStart.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at play.runsupport.Reloader$.startDevMode(Reloader.scala:234) at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.devModeServer$lzycompute$1(PlayRun.scala:74) at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.play$sbt$run$PlayRun$$anonfun$$anonfun$$anonfun$$devModeServer$1(PlayRun.scala:74) at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.apply(PlayRun.scala:100) at play.sbt.run.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3.apply(PlayRun.scala:53) at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47) [trace] Stack trace suppressed: run last compile:run for the full output. [error] (compile:run) java.lang.reflect.InvocationTargetException [error] Total time: 1 s, completed 28-Mar-2017 20:34:06

My guess here and from the last days worth of trial, error, hair tearing etc that there is an issue with which version of ch.qos.logback Play uses. I think Play defaults to the version it is using in the project. These are : -

SBT: ch.qos.logback:logback-classic:1.1.7:jar
SBT: ch.qos.logback:logback-core:1.1.7:jar

OpenImaj then has issues using the versions within Test-1.0-SNAPSHOT-jar-with-dependencies.jar ... or vice versa i.e. the versions are defaulted to those on the Jar files.

Any ideas on what I can do here?

FYI - I tried using Maven to pull down all the required libraries but encountered similar issues.

@jonhare

This comment has been minimized.

Copy link
Member

jonhare commented Mar 29, 2017

This should be possible (we've used Play and OpenIMAJ together successfully in the past). I think your problem is that you're adding the "fat" jar (the one named "...-jar-with-wependencies.jar" to your play app. You definitely don't want to do this as it will create problems with the dependencies play wants to use. The correct way to add your openimaj app jar to your play app would be by declaring it as a dependency in build.sbt as per https://www.playframework.com/documentation/2.5.x/SBTDependencies. You wouldn't need to specify any openimaj dependencies directly as they'll be picked up by sbt automatically.

Fundamentally, the steps are:

  1. build and install you java openimaj code to the local maven repository: mvn package install
  2. edit build.sbt of your play app and:
    • add the local maven repo to the search path: resolvers += ( "Local Maven Repository" at "file:///"+Path.userHome.absolutePath+"/.m2/repository" )
    • add your dependency: libraryDependencies += "your.group.id" % "Test" % "1.0-SNAPSHOT"

(Caveats: if you're using Windows, you might need to adjust the paths accordingly; I'm also not sure how this fits in with IntelliJ)

@nusynergi

This comment has been minimized.

Copy link
Author

nusynergi commented Mar 29, 2017

Thanks Jon.

I am using a Mac to build this but it will be deployed on Linux.

Quick question relating to your points above : -

  1. When you say my code, do you mean the application I have written? or the 'Test-1.0-SNAPSHOT-jar-with-dependencies.jar'?

Do I need to downlaod all the sources and compile to a new JAR or will this fat JAR 'Test-1.0-SNAPSHOT-jar-with-dependencies.jar' work in Play if I follow step 2 above?

Apologies for the novice like questions. Learning a lot of this as I go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.