Open lutnos opened 10 years ago
I see you are running the Play application in "dev" mode using sbt run. One of the limitation of the remote-repl tool (which I am planning to fix as soon as possible) is doesn't work very well if you have multiple classloaders. When you run Play in dev mode we have to deal with sbt classloaders, play classloaders and others. If you run Play using "start" (in prod mode) it should work.
One possible way to fix this problem would be to show user all the available classloaders and tool latch on to the one selected. This is pretty high in my list. I might work on this weekend.
Thanks for explaining, I had previously assumed that your reference in the video to use in production mode was solely a strength, rather than a possible source of weakness. Now I understand, I can move forwards
Yes, I now have it working using production mode
davesimac:sample_play_app dave$ ~/play/play-2.2.1/play start [info] Loading global plugins from /Users/dave/.sbt/0.13/plugins [info] Loading project definition from /Users/dave/srr/scala-remote-repl/sample_play_app/project This project uses Play 2.2.2! Update the Play sbt-plugin version to 2.2.1 (usually in project/plugins.sbt) [info] Set current project to sample_play_app (in build file:/Users/dave/srr/scala-remote-repl/sample_play_app/) (Starting server. Type Ctrl+D to exit logs, the server will remain in background) Play server process ID is 13060 [info] play - Application started (Prod) [info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000 objc[13060]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined. Running agent in remote jvm... Selected classloader sun.misc.Launcher$AppClassLoader@23b561a2 Waiting for connection at 9191
davesimac:scala-remote-repl dave$ sbt -Dconfig.file=davejars.conf "run 13060 127.0.0.1 9191" Loading /Users/dave/sbt/0.13.0/sbt/bin/sbt-launch-lib.bash [info] Loading global plugins from /Users/dave/.sbt/0.13/plugins [info] Loading project definition from /Users/dave/srr/scala-remote-repl/project [info] Set current project to remote-repl (in build file:/Users/dave/srr/scala-remote-repl/) [info] Running com.nworks.remote.repl.Main 13060 127.0.0.1 9191 Connect to 127.0.0.1:9191?[Hit enter for yes] Connected to remote REPL. Fire up your commands Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_51). Type in expressions to have them evaluated. Type :help for more information. Welcome to Remote REPL. Enjoy! scala> import play.api.Play.current import play.api.Play.current scala> import play.api.cache.Cache import play.api.cache.Cache scala> Cache.set("dave", "from remore repl") scala>
I look forward to future developments
I tried to attach to a Tomcat-app, and it didn't work, probably due to class-loader issues: Error in tomcat-log:
Running agent in remote jvm...
Selected classloader sun.misc.Launcher$AppClassLoader@44f757b9
Resetting the classloader...sun.misc.Launcher$AppClassLoader@44f757b9
Exception in thread "remote-repl-thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.nworks.remote.agent.AgentMain.startRepl(AgentMain.java:82)
at com.nworks.remote.agent.AgentMain.access$100(AgentMain.java:11)
at com.nworks.remote.agent.AgentMain$1.run(AgentMain.java:36)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.nworks.remote.agent.AgentMain.startRepl(AgentMain.java:78)
... 2 more
Caused by: java.lang.NoClassDefFoundError: scala/collection/Seq
at com.nworks.remote.repl.ServerRepl.start(ServerRepl.scala)
... 7 more
Caused by: java.lang.ClassNotFoundException: scala.collection.Seq
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 8 more
Also, I had to make minor tweaks to build.sbt to make it work with Scala-2.11.2:
import sbt.Keys._
name := "remote-repl"
organization := "net.nworks"
val agent = project.in(file("agent")).settings(
packageOptions in (Compile, packageBin) +=
Package.ManifestAttributes("Agent-Class" -> "com.nworks.remote.agent.AgentMain" ),
scalaVersion := "2.11.2"
)
val main = project.in(file(".")).aggregate(agent).settings(
unmanagedJars in Compile ~= {uj =>
Seq(Attributed.blank(file(System.getProperty("java.home").dropRight(3)+"lib/tools.jar"))) ++ uj
},
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"jline" % "jline" % "2.11",
"com.typesafe" % "config" % "1.2.0"
),
scalaVersion := "2.11.2"
)
And some minor changes to ClientRepl
(change jline imports and fix constructor-call to ConsoleReader
Are there any plans to port this to Scala-2.11 and fix the class-loader issue?
Thanks!
Yeah. Its a classloader issue. I actually have this in my todo list. Since I am getting few requests to fix this I will try to take out some time and implement this. One possible way to do this would be to show user all the available classloaders so that user can pick one hook into.
+1
My first attempt to run the repo has failed with an apparent class loader issue.
First I download and build the remote repo project:
Then in a separate terminal window I start the sample play application:
Finally trying to invoke the remote repo:
Provokes this error in the play application:
and this in the remote repo invocation:
Please let me know if I can do anything further to investigate this, or otherwise how I might get this very useful project working.
Thanks
Dave