使用javaagent和Grails的班级加载问题
我写了一个可以远程调试Web应用程序的Javaagent。它在许多框架中都可以正常工作,例如Tomcat,Jetty甚至Scala Play。由于Groovy也在JVM上运行,我想知道它可以用于圣杯。
在描述我尝试的内容之前。我应该稍微解释我的代理商。它启动了嵌入式杰特式服务器,并提供调试接口。我还编写了一个自定义类加载程序来加载我的代理使用的所有类。
因此,首先,我确保代理在Groovy本地应用程序上正常工作。然后,我将Javaagent参数添加到Java_opts,然后启动Grails应用程序。在首次阶段,码头服务器成功启动,但是当我向调试接口发送请求时,它却一无所获,并且可以在控制台中找到有关类加载的警告消息。
我严格地设计了JVM规范之后的Javaagent(我认为),并且由于它可以在其他框架中使用,所以我想知道Grails的班级加载中是否有什么特别的?
我的经纪人: https://github.com/github.com/niqub.com/uniquetruth/niquetruth/remote-debug-debug-agent-debug-agent-debug-agent /tree/grail_research
您可以简单地弄清楚如何在readme中使用它。您也可以直接使用该版本,但是需要在JAR文件中更改Jetty的日志级别。在分支代码中,我已经打开了Jetty的登录,并为Jetty Server添加了JOIN(),以便我可以更快地阻止Premain阶段和调试速度。
Java版本:1.8
Groovy版本:4.0.2
Grails版本:5.1.8
Web应用程序:Grails的默认Helloworld演示还可以。
启动应用程序后,将此请求发送到调试接口http:// localhost:8098/trace/
期望:返回一些文字
当前情况:在控制台中没有任何回报和警告:
org.eclipse.jetty.io.ManagedSelector $接受失败
java.lang.noclassdeffounderror:无法初始化类org.eclipse.jetty.server.httpoutput
甚至没有堆栈跟踪。
I wrote a javaagent that can debug web applications remotely. It works fine in many frameworks, like Tomcat, Jetty, and even Scala Play. Since Groovy is also running on JVM, I wondered could it be used for Grails.
Before describing what I've tried. I should explain my agent a little. It starts an embedded-jetty server and provides debugging interfaces. I also wrote a custom class loader to load all classes my agent uses.
So, first I ensured the agent works fine on groovy local application. Then I added javaagent parameters to JAVA_OPTS, and started Grails application. In premain phase, the jetty server started successfully, but when I sent requests to the debugging interface, it returned nothing and a warning message about class loading could be found in the console.
I designed my javaagent following the JVM specification strictly(I think), and since it can be used in other frameworks, I wonder is there anything special in Grails' class loading?
My agent: https://github.com/uniquetruth/remote-debug-agent/tree/grail_research
You can figure out how to use it in README simply. You can use the release directly too, but need to change jetty's log level in the jar file. In the branch code, I've already turned Jetty's log on, and added join() for Jetty server, so that I can block premain phase and debug faster.
Java version: 1.8
Groovy version: 4.0.2
Grails version: 5.1.8
web application: the default helloworld demo of Grails is ok.
after application starts, send this request to debug interface http://localhost:8098/trace/
expectation: return some text
current situation: nothing returns and warning found in console:
org.eclipse.jetty.io.ManagedSelector$Accept failed
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpOutput
There is even no stack trace.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我自己想了。这不是关于类加载,而Grails以分叉模式启动应用程序,如果我将Java_opt设置在Shell中,则Grails Cli将其采用,而不是真实的应用程序。
在分叉模式下将Java_opts添加到Grails应用程序的正确方法是编辑Build.gradle文件中的Bootrun配置。
I think I figured it out by myself. It's not about class loading, Grails starts applications in forked mode, if I set JAVA_OPTS in shell, the grails CLI takes it, not the real application.
The correct way to add JAVA_OPTS to grails application in forked mode is to edit the bootRun configuration in the build.gradle file.