gpt4 book ai didi

java - 远程调试tomcat时Intellij断点不命中

转载 作者:行者123 更新时间:2023-12-02 01:01:16 33 4
gpt4 key购买 nike

环境:

  • 操作系统:Mac 10.13.6
  • Java-8
  • Tomcat-7
  • Intellij 社区 2019.3
  • Gradle 5.2.1

命令行输出:

$ export GRADLE_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=address=5005"
$ ./gradlew myproj-web-java:tomcatRunWar
Listening for transport dt_socket at address: 5005
Starting a Gradle Daemon, 2 incompatible and 2 stopped Daemons could not be reused, use --status for details

运行/调试配置:

Debugger Mode: Attach to remote JVM
Use module classpath: myproj-parent:myproj-web-java:main

开始调试,Intellij输出:

Connected to the target VM, address: 'localhost:5005', transport: 'socket'

我在 Controller 中添加了断点并通过浏览器访问该页面。页面渲染正确,我可以在控制台中看到输出的日志,但断点没有命中。

<小时/>

如果我在 Intellij 中暂停程序,我可以看到主线程的堆栈:

kevent0:-1, KQueueArrayWrapper (sun.nio.ch)
poll:198, KQueueArrayWrapper (sun.nio.ch)
doSelect:117, KQueueSelectorImpl (sun.nio.ch)
lockAndDoSelect:86, SelectorImpl (sun.nio.ch)
select:97, SelectorImpl (sun.nio.ch)
select:101, SelectorImpl (sun.nio.ch)
read:179, SocketConnection$SocketInputStream (org.gradle.internal.remote.internal.inet)
fill:139, Input (com.esotericsoftware.kryo.io)
require:159, Input (com.esotericsoftware.kryo.io)
readInt:308, Input (com.esotericsoftware.kryo.io)
readSmallInt:120, KryoBackedDecoder (org.gradle.internal.serialize.kryo)
read:139, DefaultSerializerRegistry$TaggedTypeSerializer (org.gradle.internal.serialize)
read:36, Serializers$StatefulSerializerAdapter$1 (org.gradle.internal.serialize)
receive:80, SocketConnection (org.gradle.internal.remote.internal.inet)
receive:75, DaemonClientConnection (org.gradle.launcher.daemon.client)
receive:35, DaemonClientConnection (org.gradle.launcher.daemon.client)
monitorBuild:211, DaemonClient (org.gradle.launcher.daemon.client)
executeBuild:179, DaemonClient (org.gradle.launcher.daemon.client)
execute:142, DaemonClient (org.gradle.launcher.daemon.client)
execute:93, DaemonClient (org.gradle.launcher.daemon.client)
run:52, RunBuildAction (org.gradle.launcher.cli)
execute:207, Actions$RunnableActionAdapter (org.gradle.internal)
execute:402, CommandLineActionFactory$ParseAndBuildAction (org.gradle.launcher.cli)
execute:375, CommandLineActionFactory$ParseAndBuildAction (org.gradle.launcher.cli)
execute:37, ExceptionReportingAction (org.gradle.launcher.cli)
execute:23, ExceptionReportingAction (org.gradle.launcher.cli)
execute:368, CommandLineActionFactory$WithLogging (org.gradle.launcher.cli)
execute:298, CommandLineActionFactory$WithLogging (org.gradle.launcher.cli)
doAction:36, Main (org.gradle.launcher)
run:45, EntryPoint (org.gradle.launcher.bootstrap)
invoke0:-1, NativeMethodAccessorImpl (sun.reflect)
invoke:62, NativeMethodAccessorImpl (sun.reflect)
invoke:43, DelegatingMethodAccessorImpl (sun.reflect)
invoke:498, Method (java.lang.reflect)
runNoExit:60, ProcessBootstrap (org.gradle.launcher.bootstrap)
run:37, ProcessBootstrap (org.gradle.launcher.bootstrap)
main:23, GradleMain (org.gradle.launcher)

主线程或其他线程中没有我的代码。但是,如果我检查进程列表,似乎 tomcat 没有独立的 jvm 进程。

当程序暂停时,我仍然可以在控制台输出暂停时访问该页面。

最佳答案

GRADL_OPTS 设置为这样 - 您将为 Gradle 守护进程本身启动调试进程,而不是为 Tomcat 服务器实际运行的 fork Java 进程启动。

您可以使用Gradle Run/Debug Configuration用于启动 Tomcat 服务器,您可以在其中为 fork 进程指定 JVM 选项:

enter image description here

截图取自这篇文章:Debugging a spring-mvc web-app with the gradle-tomcat-plugin and IntelliJ IDEA

关于java - 远程调试tomcat时Intellij断点不命中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60599014/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com