Java IntelliJ IDEA 调试器不适用于 Grails 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19247944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 15:26:18  来源:igfitidea点击:

IntelliJ IDEA Debugger isn't working on a Grails Project

javadebugginggrailsintellij-idea

提问by ricardogobbo

I can't debug my code in IntelliJ IDEA. When debug mode is active and running, but the breakpoints don't have that "v" checked that represents a valid and stoppable breakpoint.

我无法在 IntelliJ IDEA 中调试我的代码。当调试模式处于活动状态并正在运行时,但断点没有检查表示有效且可停止的断点的“v”。

See the image:

看图:

enter image description here

在此处输入图片说明

I really search on the web for an answer. What am I supposed to do?

我真的在网上搜索答案。我应该做些什么?

采纳答案by Igors

I have tried all mentioned here without success. The only helpful information is here.

我已经尝试了这里提到的所有内容,但都没有成功。唯一有用的信息在这里

In essence you should disable forked execution by adding the following to grails-app/conf/BuildConfig.groovy:

本质上,您应该通过添加以下内容来禁用分叉执行grails-app/conf/BuildConfig.groovy

grails.project.fork = [
    test: false,
    run: false
]

Now debugging is available in IntelliJ IDEA Ultimate Edition v.12.1.6 just by ordinary Debug without Remote debugging. Tested on Grails 2.3.1, Java 1.7.0_45, Windows 7 64-bit.

现在 IntelliJ IDEA Ultimate Edition v.12.1.6 可以通过普通 Debug 进行调试,无需远程调试。在 Grails 2.3.1、Java 1.7.0_45、Windows 7 64 位上测试。

回答by akn

Try this:

尝试这个:

In idea choose Edit configurationsfrom list next to 'run' button. Then add Remote, choose your name and left default remote configuration settings. (port 5005 etc)

在想法中,从“运行”按钮旁边的列表中选择“编辑配置”。然后添加Remote,选择您的名字并保留默认的远程配置设置。(端口 5005 等)

Run your app from console by using

使用以下命令从控制台运行您的应用程序

grails run-app --debug-fork

In idea, choose your configuration from list and hit debug button when console display info:

在想法中,从列表中选择您的配置并在控制台显示信息时点击调试按钮:

Listening for transport dt_socket at address: 5005

回答by Andrey Chaschev

Just three guesses:

只是三个猜测:

Try running run-app, not run-war, both should work, but may be run-warjust isn't working.

尝试运行run-app,而不是run-war,两者都应该可以工作,但可能run-war只是不工作。

Or: try debugging remotely from console:

或者:尝试从控制台远程调试:

grails -debug run-appand then connect with Remote Debug in Idea.

grails -debug run-app然后连接Idea中的Remote Debug。

Or, the last resort: downgrading your project to previous Grails versions could work. Yes, this is really annoying.

或者,最后的手段:将您的项目降级到以前的 Grails 版本是可行的。是的,这真的很烦人。

Hope this helps.

希望这可以帮助。

回答by Hyman_kerouac

Since Grails 2.3, forked executionfor several Grails commands (e.g. run-app, test-app) was introduced. If you just debug a Grails application from IntelliJ IDEA, the GrailsStarterprocess will be started with debug options on. The output on the IDEA console will be:

从 Grails 2.3 开始,引入了几个 Grails 命令(例如,)的分叉执行。如果您只是从 IntelliJ IDEA 调试 Grails 应用程序,则该过程将在调试选项打开的情况下启动。IDEA 控制台上的输出将是:run-apptest-appGrailsStarter

/usr/lib/jvm/default-java/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:59935,suspend=y,server=n [...] /opt/idea-IU-133.330/lib/idea_rt.jar org.codehaus.groovy.grails.cli.support.GrailsStarter [...] run-app Connected to the target VM, address: '127.0.0.1:59935', transport: 'socket'

The application itself will be started in a separate process named ForkedTomcatServer. This is where your code runs and where your debugger should actually connect to.

应用程序本身将在名为 的单独进程中启动ForkedTomcatServer。这是您的代码运行的地方,也是您的调试器实际连接的地方。

To accomplish that, set debug: truein BuildConfig.groovyat the runconfiguration of grails.project.fork. Just run Grails now from IDEA (do not debug) and you will see the following line in the console when the application is ready to serve HTTP requests:

为了实现这个目标,设定debug: trueBuildConfig.groovyrun的配置grails.project.fork。现在只需从 IDEA 运行 Grails(不要调试),当应用程序准备好为 HTTP 请求提供服务时,您将在控制台中看到以下行:

Listening for transport dt_socket at address: 5005

This is where you want to direct a separate remote run configurationto. As soon as your remote debugger connected, issue a HTTP request and debugging will work.

这是您要将单独的远程运行配置定向到的位置。一旦你的远程调试器连接,发出一个 HTTP 请求,调试就会工作。

You can also disable forked executionfor compile/test/run/war/console Grails commands entirely by setting the value associated with the command entry in grails.project.forkto false. But then you will lose the benefits for forked execution added in Grails 2.3.

您还可以禁用叉执行的编译/测试/运行/战争/ Grails的控制台完全由设置在该命令项关联的值命令grails.project.forkfalse。但是,您将失去 Grails 2.3 中添加的分叉执行的好处。

回答by daimon

I tested with intellij latest with Grails 2.3.4 on Mac Os x Lion.

我在 Mac Os x Lion 上使用 Grails 2.3.4 使用最新的 Intellij 进行了测试。

Then I tried Igors's advice and it is working without forked mode.

然后我尝试了 Igors 的建议,它在没有分叉模式的情况下工作。

grails.project.fork = [
    test: false,
    run: false
]

Please check for detail grails documentation

请查看详细的grails 文档

if you want to debug forked mode you should check following blog post explainsvery well.

如果你想调试分叉模式,你应该很好地查看以下博客文章。

http://blog.jdriven.com/2013/12/grails-goodness-debugging-app-forked-mode/

http://blog.jdriven.com/2013/12/grails-goodness-debugging-app-forked-mode/

回答by Beaumont Muni

This should not ever be the default configuration and only be left to the individual's choice. It's a freakin pain to do two configurations just get this thing running in debug mode in intellij. First you have to setup or modify the normal run configuration by adding "--debug-fork" after run-app. Second, you have to configure remote debugging , while accepting all the defaults. Then you have to run the run configuration, and when that's running, you run the debug configuration. What a pain. I prefer totally doing away with running without the forked option while developing. Time is money and I don't have time to monkey around. See Mr.HAKI explanation on doing this. http://blog.jdriven.com/2013/12/grails-goodness-debugging-app-forked-mode/

这不应该是默认配置,只能由个人选择。做两个配置只是让这个东西在intellij的调试模式下运行是一件非常痛苦的事情。首先,您必须通过在 run-app 之后添加“--debug-fork”来设置或修改正常的运行配置。其次,您必须配置远程调试,同时接受所有默认值。然后你必须运行运行配置,当它运行时,你运行调试配置。多么痛苦。我更喜欢在开发时完全取消没有分叉选项的运行。时间就是金钱,我没有时间胡闹。参见 Mr.HAKI 对此的解释。http://blog.jdriven.com/2013/12/grails-goodness-debugging-app-forked-mode/

回答by GhostEcho

Debugging a grails (2.3+) application can be done in two ways.

可以通过两种方式调试 grails (2.3+) 应用程序。

1. Simple solution: disable debug

1.简单的解决办法:禁用调试

edit BuildConfig.groovy:

编辑 BuildConfig.groovy:

grails.project.fork = [
    war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, fork ...
    run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, fork ...

to

grails.project.fork = [
    war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, fork ...
    run: false,

Pros:

优点:

  • Simple to do (and get on with your development)
  • 操作简单(并继续您的开发)

Cons:

缺点:

  • This removes the ability to perform runtime code replacement. This means that if you change code, it will no longer be picked up automatically and you will need to restart the application to see the changes. This can be very time consuming.
  • 这消除了执行运行时代码替换的能力。这意味着如果您更改代码,它将不再被自动选取,您将需要重新启动应用程序才能看到更改。这可能非常耗时。

2. Involved solution: debug forked runtime

2. 涉及解决方案:debug forked runtime

This is a somewhat more complex solution where you attach a debugger to a running grails application. It is described in more detail in this blog post.

这是一个稍微复杂一些的解决方案,您可以在其中将调试器附加到正在运行的 grails 应用程序。这篇博文中有更详细的描述。

After setup you have an extra run configuration that allows you to start up grails in forked mode, and yet another extra run configuration that allows you to debug that forked mode. The catch is that you are required to start both or it does not work.

设置后,您有一个额外的运行配置,允许您在分叉模式下启动 grails,还有另一个额外的运行配置,允许您调试该分叉模式。问题是您必须同时启动两者,否则它不起作用。

Pros:

优点:

  • You have both debugging and runtime code replacement
  • This does not interfere with starting the application in normal mode. (i.e. you have extra options)
  • 你有调试和运行时代码替换
  • 这不会干扰在正常模式下启动应用程序。(即你有额外的选择)

Cons:

缺点:

  • Setting up takes a little bit of time
  • Starting up in debug mode requires is a more complex two step process (i.e. it takes longer)
  • 设置需要一点时间
  • 在调试模式下启动需要一个更复杂的两步过程(即需要更长的时间)

Considerations

注意事项

Solution 2 is mostly superior in the sense that it allows flexibility. I personally don't use debug a lot, so just start in normal mode. When I want to debug, I restart in debug mode.

解决方案 2 在允许灵活性的意义上更胜一筹。我个人不经常使用调试,所以只需在正常模式下启动。当我想调试时,我以调试模式重新启动。

Solution 1 is strictly better if you need to debug and also need to restart a lot. For instance when you are working on your domain classes or database setup in your BootStrap.groovy.

如果您需要调试并且还需要大量重新启动,则解决方案 1 绝对更好。例如,当您在 BootStrap.groovy 中处理域类或数据库设置时。

回答by Peter Kahn

Did you see this article? It details the how to step by step and got me past my problem.

你看到这篇文章了吗?它详细说明了如何一步一步地解决我的问题。

http://mrhaki.blogspot.com/2013/12/grails-goodness-debugging-app-in-forked.html

http://mrhaki.blogspot.com/2013/12/grails-goodness-debugging-app-in-forked.html

回答by biniam

Checkout thisblog about Debugging Grails Forked Mode.

查看这篇关于调试 Grails 分叉模式的博客。

回答by Ed J

None of the other answers work for me on Grails 3.x in 2016 w/ Intellij 15.0.4. This does work for me:

在 2016 年使用 Intellij 15.0.4 的 Grails 3.x 上,其他任何答案都不适合我。这对我有用:

Start grails in intellij with this command:

使用以下命令在 intellij 中启动 grails:

run-app  --debug-jvm

The console should output: "Listening for transport dt_socket at address: 5005 Grails application running at http://localhost:8080in environment: development"

控制台应输出:“在地址:5005 Grails application running at http://localhost:8080in environment: development处侦听传输 dt_socket ”

Now you can add a new configuration of type, "Remote", in Intellij. Then start it with its defaults.

现在,您可以在 Intellij 中添加类型为“Remote”的新配置。然后使用其默认值启动它。

And the new debug console window should write: "Connected to the target VM, address: 'localhost:5005', transport: 'socket'"

新的调试控制台窗口应该写:“连接到目标虚拟机,地址:'localhost:5005',传输:'socket'”

Done.

完毕。

For those interested, the reference to grails 3.x documentation for starting a debuggable server is at section 2.8, runningAndDebuggingAnApplication:

对于那些感兴趣的人,有关启动可调试服务器的 grails 3.x 文档的参考位于第 2.8 节,runningAndDebuggingAnApplication:

http://grails.github.io/grails-doc/3.1.x/guide/gettingStarted.html#runningAndDebuggingAnApplication

http://grails.github.io/grails-doc/3.1.x/guide/gettingStarted.html#runningAndDebuggingAnApplication

"There are several ways to execute the Application class, if you are using an IDE then you can simply right click on the class and run it directly from your IDE which will start your Grails application. This is also useful for debugging since you can debug directly from the IDE without having to connect a remote debugger when using the run-app --debug-jvm command from the command line."

“有几种方法可以执行 Application 类,如果您使用的是 IDE,那么您只需右键单击该类并直接从您的 IDE 运行它,这将启动您的 Grails 应用程序。这对于调试也很有用,因为您可以调试从命令行使用 run-app --debug-jvm 命令时,无需连接远程调试器,即可直接从 IDE 使用。”

Important Note. When I tried the "simply right click on the class and run it directly from your IDE", the app did start. However, all requests I sent to my controller resulted in 500 errors with message: "Could not resolve view with name '/myendpoint' in servlet with name 'grailsDispatcherServlet'.

重要的提示。当我尝试“只需右键单击该类并直接从您的 IDE 运行它”时,该应用程序确实启动了。但是,我发送到我的控制器的所有请求都导致了 500 个错误消息:“无法解析名为 'grailsDispatcherServlet' 的 servlet 中名为 '/myendpoint' 的视图。

So, I reverted back to the instructions above.

所以,我又回到了上面的说明。