【发布时间】:2016-08-02 03:40:18
【问题描述】:
在离开 Grails 几年后,我再次与 Grails 合作。我正在使用 IntelliJ 2016.01 和 Grails 3.1.4。这应该很容易,对吧?一切正常,除了我不能像以前那样从 IntelliJ 中启动调试器。在以前的生活中,我使用 IJ10 和 Grails 1.0.5。
通过各种搜索,我发现更改源自 Grails 2.3,当时它们出于各种原因开始以分叉模式运行。在不了解所有技术细节的情况下,我的理解是这样做是出于性能原因。无论如何,我能够找到解决方法,但似乎还有很长的路要走。有谁知道更好的方法?我错过了什么?
我创建了一个 ant 任务来调用 grails run-app:
<target name="start-debug-grails">
<exec executable="cmd">
<arg value="/c"/>
<arg value="start"/>
<arg value="grails"/>
<arg value="run-app"/>
<arg value="--debug-jvm"/>
</exec>
</target>
如果您单独运行此任务,您会在新的 cmd 窗口中看到 grails 在调试模式下运行: |正在运行应用程序... 在地址:5005 监听传输 dt_socket
然后我在 IntelliJ 中创建了一个“远程”运行/调试配置以连接到端口 5005。我确实有可用于此运行/调试配置的调试按钮,所以我单击调试。它附着得很好。
首先我在 IntelliJ 中看到了这个:
Connected to the target VM, address: 'localhost:5005', transport: 'socket'
稍后,cmd 窗口会更新以显示应用程序处于调试模式:
| Running application...
Listening for transport dt_socket at address: 5005
Grails application running at http://localhost:8080 in environment: development
此时我可以毫无问题地在端口 8080 上导航应用程序。我可以对代码的某些部分进行更改,例如控制器,它将被编译并立即可用。是的。
我更进一步,添加了 stop ant 任务(这比应该做的要难一些),这样我就可以执行这两个任务(如果进程正在运行,首先停止)然后开始:
<target name="stop-debug-grails" depends="-stop-debug-init, -stop-debug-kill"/>
<target name="-stop-debug-init">
<!--check if process is running-->
<exec executable="jps">
<arg value="-l"/>
<redirector outputproperty="process.pid">
<outputfilterchain>
<linecontains>
<contains value="grails"/>
</linecontains>
<replacestring from=" org.grails.cli.GrailsCli"/>
</outputfilterchain>
</redirector>
</exec>
<echo>
${process.pid}
</echo>
<condition property="do.kill">
<not>
<!--checks to make sure pid is non blank before calling kill-process-->
<equals arg1="${process.pid}" arg2="" />
</not>
</condition>
</target>
<target name="-stop-debug-kill" if="do.kill">
<echo>
killing process ${process.pid}
</echo>
<exec executable="taskkill" osfamily="winnt">
<arg value="/F"/>
<arg value="/PID"/>
<arg value="${process.pid}"/>
</exec>
<exec executable="kill" osfamily="unix">
<arg value="-9"/>
<arg value="${process.pid}"/>
</exec>
</target>
我必须编辑我的 start-debug-grails 任务以等待 grails 开始侦听端口 5005。
<!--delay to let the server start-->
<sleep seconds="20"/>
现在我可以通过单击 IntelliJ 中远程进程的调试来按照我习惯的方式在 IntelliJ 中进行调试。有谁知道更好的方法来处理这个问题?
【问题讨论】:
标签: debugging grails intellij-idea