【问题标题】:Debugging with exec-maven-plugin使用 exec-maven-plugin 进行调试
【发布时间】:2020-10-04 22:54:42
【问题描述】:

我正在使用 exec-maven-plugin 执行我的 java 应用程序并使用以下设置从我的 IDE (IntelliJ) 运行调试:

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>exec-maven-plugin</artifactId>
   <version>1.4.0</version>
   <executions>
      <execution>
        <id>exec_1</id>
        <phase>deploy</phase>
        <goals>
            <goal>java</goal>
        </goals>
      </execution>
   </executions>
   <configuration>
       <mainClass>com.myapp.app</mainClass>
   </configuration>
</plugin>

而且效果很好。然后,我更改我的设置以执行一个现实的java 命令行,它将运行相同的应用程序:

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>exec-maven-plugin</artifactId>
   <version>3.0.0</version>
   <executions>
      <execution>
        <id>exec_1</id>
        <phase>deploy</phase>
        <goals>
            <goal>exec</goal>
        </goals>
      </execution>
   </executions>
   <configuration>
      <executable>java</executable>
       <arguments>
           <argument>-cp</argument>
           <argument>
               "dir1";"dir2;etc..."
           </argument>
           <argument>com.myapp.app</argument>
       </arguments>
   </configuration>
</plugin>

它可以执行应用程序,但它不会将调试器附加到 IDE。那么,我可以添加什么额外的参数来让它捕获调试中断?

【问题讨论】:

  • 为什么不在 IDEA 中创建一个运行配置并在没有 Maven 的情况下运行它?
  • 或运行构建到您需要的阶段并从命令行继续。使用 dependency:buildclasspath 目标来获取你的类路径

标签: java debugging intellij-idea exec-maven-plugin


【解决方案1】:

当您在调试模式下启动 maven 目标时 - 您正在为 Maven 目标进程启动调试,但您需要调试由 Maven 目标 JVM 进程分叉的进程。为此,您可以

  • 为此进程指定远程调试 JVM 选项,如 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000(参见this SO 帖子),然后在 IDE 中启动 Remote Debug Configuration。有关 IDE 中的远程调试,请参阅 this tutorial
  • 使用 IDE 自己的 Run/Debug Configuration 来启动和调试应用程序。

【讨论】:

    猜你喜欢
    • 2020-01-25
    • 2012-03-13
    • 2014-04-23
    • 2016-10-17
    • 2018-07-09
    • 2016-01-31
    • 1970-01-01
    • 2018-03-20
    • 2011-07-03
    相关资源
    最近更新 更多