You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

远程调试Tomcat时IntelliJ IDEA断点无法触发问题

Hey there, let's dig into why your remote debugging isn't hitting those breakpoints. First, let's lay out all the details you provided, then break down the root cause and fixes:

Remote Debugging Breakpoints Not Triggering with Gradle + Tomcat 7

Environment Setup

  • OS: Mac 10.13.6
  • Java: Java 8
  • Tomcat: Tomcat 7
  • IntelliJ: Community 2019.3
  • Gradle: 5.2.1

Steps You Took

  1. Set Gradle debug options via terminal:
    export GRADLE_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=address=5005"
    
    Quick note: There's a small typo here — the suspend parameter should be suspend=n (or suspend=y if you want to wait for debugger attach before starting) followed by address=5005, like "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
  2. Ran the Tomcat task:
    ./gradlew myproj-web-java:tomcatRunWar
    
    The output included:

    Listening for transport dt_socket at address: 5005
    (Plus Gradle Daemon-related messages)

IntelliJ Debug Config

  • Mode: Attach to remote JVM
  • Module Classpath: myproj-parent:myproj-web-java:main

What You Observed

  • IntelliJ confirms the connection:

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

  • Browser loads the page normally, console logs appear, but breakpoints in your controller don't trigger
  • When pausing the debugger, the main thread stack shows no business application code
  • No separate Tomcat JVM process is visible in your process list
  • The page remains accessible even when the debugger is paused

Why This Is Happening & How to Fix It

The key clues here are the missing Tomcat process and untriggered breakpoints — this means Tomcat is running inside the Gradle Daemon's JVM, not a separate process. When you attached to port 5005, you're debugging the Gradle Daemon itself, not the Tomcat instance hosting your web app.

Here's how to fix this:

  1. Configure Gradle to fork a separate JVM for Tomcat:
    Open the build.gradle file for your myproj-web-java module, and add this to the Tomcat configuration:
    tomcat {
        fork = true // Forces Tomcat to run in its own independent JVM
        jvmArgs = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5006"]
        // Use suspend=y if you want Tomcat to wait for the debugger to attach before starting up
    }
    
  2. Update your terminal and debug setup:
    • Remove the GRADLE_OPTS export you set earlier (we're now defining debug args directly for Tomcat's dedicated JVM)
    • Run ./gradlew myproj-web-java:tomcatRunWar again — you'll see Tomcat listening for debug connections on port 5006 now
    • Go to your IntelliJ remote debug config, change the port to 5006, and re-attach the debugger
  3. Double-check classpath alignment:
    Make sure the module classpath in your debug config (myproj-parent:myproj-web-java:main) matches the runtime classpath of your Tomcat app. If IntelliJ feels out of sync with Gradle, run File > Sync Project with Gradle Files to ensure everything's aligned.

One last sanity check: Verify your breakpoints are set on code that's actually being executed. For example, place a breakpoint in the exact controller method that handles the browser request you're testing — breakpoints on unused code or interfaces won't trigger.

内容的提问来源于stack exchange,提问作者user1633272

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 21:52:50