5

I'm struggling to debug an application that builds as a Sling bundle. The application is almost entirely Groovy code (I have the Groovy Eclipse plug-in), and Eclipse (using Maven) is building the .jar and installing it in Sling without any problems.

However, it's not able to debug. I have followed instructions to set up remote debugging, which I gather is necessary for debugging Sling apps - specifically, I launch Sling with the following command:

java -Xdebug -Xnoagent -Djava.io.tmpdir=/c/Users/nickgolding1/temp -Xmx1024m -Xrunjdwp:transport=dt_socket,address=30303,server=y,suspend=n -jar org.apache.sling.launchpad-6-SNAPSHOT-standalone.jar -p 8080

... and then set up a debug configuration in Eclipse, of type "Remote Java Application", pointing to my project, Connection Type "Standard (Socket Attach)", host localhost, port 30303. This configuration seems to start ok - at least, I don't get any feedback suggesting it hasn't - but breakpoints I set in the Groovy code don't actually break execution of requests to the Sling app.

I've seen a couple of posts on various forums that show people having problems debugging Groovy code via the Remote Java App configuration, where they don't have a problem with Java code. Unfortunately my app is all Groovy and no Java, so I can't verify this is the case here.

Any thoughts appreciated!

user987339
  • 10,519
  • 8
  • 40
  • 45
Nick Golding
  • 53
  • 1
  • 6

1 Answers1

4

First, a suggestion. Set suspend=y in your Xrunjdwp:transport option. This will suspend in main and will give you a better idea as to whether or not your problem is with your debug options or the Groovy code.

Now, on to something more complicated. Yes. There are some issues regarding debugging of remote Groovy code. The problem generally comes about when Groovy code is loaded dynamically. In this case the debug name often does not match the source name and the debugger does not know how to match the dynamically loaded class file with the original source code.

One such problem is described here (and there are no doubt other places where similar things happen): https://jira.springsource.org/browse/SPR-7113

So, my suggestion to you is that if possible you should ensure that your groovy code is pre-compiled before being sent to the server. (And also set suspend=y.)

Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
  • 1
    Thanks. `suspend=y` showed me that the debug options are working (in that it waited for Eclipse to start debugging and then successfully started). So it looks like the problem is with Groovy. Your precompilation suggestion is good but I'm pretty sure my Groovy code is being precompiled - certainly the Maven build output claims that it's compiling them. – Nick Golding Mar 06 '12 at 10:35
  • Also, make sure that your groovy sources are included in the source lookup path of your remote launch config in Eclipse. – Andrew Eisenberg Mar 06 '12 at 18:34
  • They weren't, good point - but they are now, and it's still not debugging even after a clean and redeploy. – Nick Golding Mar 13 '12 at 13:46
  • Any chance you can set a breakpoint in a Java class and then step into Groovy code? – Andrew Eisenberg Mar 13 '12 at 14:43
  • I don't have any Java classes that call into Groovy code, but interestingly when I hit a breakpoint in Java and step out (to get back to the Groovy code that called it), it claims that the source file is not available - even once I've added the Groovy source files to the source lookup path on the launch config. – Nick Golding Mar 15 '12 at 09:52
  • Clearly, there is some sort of naming issue in that even when you stop the debugger in a groovy class and ensure that the source code is on the lookup path, the debugger can't find it. Now, other than that, I can't say much more w/o looking at the project. It could have something to do with how sling or apache felix is loading the classes. – Andrew Eisenberg Mar 15 '12 at 20:16
  • Hmm... It does sound a lot like the naming issue you suggested in your original answer, but I'm *sure* the classes are being compiled before installation. I'll take a closer look. Thanks for your help so far! – Nick Golding Mar 16 '12 at 17:21
  • Any luck with this by any chance? – justin Nov 26 '12 at 20:14
  • Sorry Justin, I didn't spot your question! I think I did get this working in the end - I think it might have been that Eclipse wasn't recognising my project as a Groovy project, and once I'd done that it worked ok? But I'm not 100% sure, sorry - I moved onto a new project not long after this question and I can't recall the state I got to when I left :-( – Nick Golding Feb 06 '13 at 12:02