简体   繁体   English

在JRuby和Java之间进行调试

[英]Debugging between JRuby and Java

I have a large Java project that uses some Ruby scripts (primarily because of Ruby's support for "yield"). 我有一个使用某些Ruby脚本的大型Java项目(主要是因为Ruby支持“ yield”)。 The Ruby code calls Java code which calls more Ruby code. Ruby代码调用Java代码,而Java代码又调用了更多Ruby代码。 It's very interleaved, but everything is driven from Java. 它是非常交错的,但是所有内容都是由Java驱动的。

I'm using embedded jruby-standalone and building a jar-with-dependencies (via maven). 我正在使用嵌入式jruby-standalone并构建具有依赖关系的jar(通过maven)。 I'm using a maven plugin to run jrubyc and generate .java files which maven compiles for me. 我正在使用一个maven插件运行jrubyc并生成.java文件,这些文件将由maven为我编译。

When I run the jar-with-dependencies, I can attach my debugger to the Java process with no problems, but I'd really love to be able to debug the Ruby code. 当我运行jar-with-dependencies时,我可以毫无问题地将调试器连接到Java进程,但是我真的很希望能够调试Ruby代码。 Is there a solution for this? 有解决方案吗?

I'm not launching any kind of jruby executable to which I could attach arguments. 我没有启动任何可以附加参数的jruby可执行文件。 It's embedded in the jar and invoked via java -jar. 它嵌入在jar中,并通过java -jar调用。

You could use the gem pry-remote . 您可以使用gem pry-remote

Unlike pry , it does not require the process to be launched from a terminal (or a terminal emulator if you're on Windows). pry不同,它不需要从终端(或终端仿真器,如果您使用Windows)启动该进程。

It's not really a debugger per se, but if you add binding.remote_pry in your code where you wish to observe and react within that context (you could for example catch an exception), this would put pry in waiting mode for a remote connection, and from another terminal you should be able to connect to this process and debug it. 它本身并不是真正的调试器,但是如果您在代码中希望在该上下文中进行观察和响应的地方添加binding.remote_pry (例如,可以捕获异常),这将使pry处于等待模式以等待远程连接,并且从另一个终端,您应该能够连接到该过程并对其进行调试。

2 minutes hands-on tutorial is available here . 2分钟实践教程,请点击这里

Drawbacks: 缺点:

  • you cannot have 2 pry remote sessions. 您不能进行2次撬动远程会话。
  • your code must contain the right 'debugging' condition 您的代码必须包含正确的“调试”条件

I use this in pre-deployment environments when developing web apps with jruby, h2 and jetty server. 在使用jruby,h2和jetty服务器开发Web应用程序时,我在部署前环境中使用了此功能。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM