我正在使用 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。那么,我可以添加什么附加参数来使其捕获调试中断?
最佳答案
当您在 Debug模式下启动 Maven 目标时 - 您正在启动 Maven 目标进程的调试,但您需要调试由 Maven 目标 JVM 进程 fork 的进程。为此,您可以
- 为此进程指定远程调试 JVM 选项,例如
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000
(请参阅 this SO 帖子)然后启动Remote Debug Configuration在IDE中。请参阅this tutorial关于IDE中的远程调试。 - 使用IDE自带的Run/Debug Configuration用于启动和调试应用程序。
关于java - 使用 exec-maven-plugin 进行调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62389740/