Grails 3在IntelliJ中调试

big*_*C28 4 debugging grails intellij-idea

几年后,我再次与Grails合作.我正在使用IntelliJ 2016.01和Grails 3.1.4.馅饼应该很容易,对吗?一切正常,但我不能像以前那样从IntelliJ中启动调试器.在以前的生活中,我使用IJ10和Grails 1.0.5.

通过各种搜索,我发现当Grails 2.3由于各种原因开始以分叉模式运行时,这些变化起源于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>
Run Code Online (Sandbox Code Playgroud)

如果您自己运行此任务,您会看到grails在新的cmd窗口中以调试模式运行:| 正在运行应用程序...在地址:5005处侦听传输dt_socket

然后我在IntelliJ中创建了一个"远程"运行/调试配置,以连接到端口5005.我有调试按钮可用于此运行/调试配置,所以我单击调试.它很好.

首先我在IntelliJ中看到这个:

Connected to the target VM, address: 'localhost:5005', transport: 'socket'
Run Code Online (Sandbox Code Playgroud)

然后片刻之后更新cmd窗口以显示应用程序处于调试模式:

| Running application...
Listening for transport dt_socket at address: 5005
Grails application running at http://localhost:8080 in environment: development
Run Code Online (Sandbox Code Playgroud)

此时我可以在端口8080上导航应用程序没有问题.我可以对代码的某些部分进行更改,例如控制器,它将被编译并立即可用.是啊.

我更进了一步并添加了停止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>
Run Code Online (Sandbox Code Playgroud)

我不得不编辑我的start-debug-grails任务,等待grails开始监听端口5005.

<!--delay to let the server start-->
<sleep seconds="20"/>
Run Code Online (Sandbox Code Playgroud)

现在,我可以通过单击IntelliJ中远程进程的调试,以我习惯的方式在IntelliJ中进行调试.有谁知道更好的方法来处理这个?

use*_*614 5

Debuggin在grails中非常简单3.打开Application.groovy类,然后单击debug