gpt4 book ai didi

java - IntelliJ 和 Eclipse : debug Java application started by Maven exec:exec

转载 作者:太空宇宙 更新时间:2023-11-04 13:49:02 25 4
gpt4 key购买 nike

在我的项目中,我有一个配置,例如

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<commandlineArgs>${additionalExecArgs} -jar ${project.build.directory}/someDir/some.jar</commandlineArgs>
<executable>java</executable>
<classpathScope>runtime</classpathScope>
</configuration>
</execution>
</executions>
</plugin>

使用 Maven exec:exec 启动可执行 JAR。additionalExecArgs 属性默认为空。

在 NetBeans 中,我可以通过在 nbactions.xml 文件中指定以下操作来运行此目标:

<action>
<actionName>run</actionName>
<goals>
<goal>exec:exec</goal>
</goals>
</action>

为了在 NetBeans 中调试此目标,我已将以下操作添加到 nbactions.xml 文件中:

<action>
<actionName>debug</actionName>
<goals>
<goal>exec:exec</goal>
</goals>
<properties>
<jpda.listen>true</jpda.listen>
</properties>
<activatedProfiles>
<activatedProfile>debug</activatedProfile>
</activatedProfiles>
</action>

因此,除了运行 exec:exec 之外,还将 NetBeans (?) 属性 jpda.listen 设置为 true 并激活 Maven 配置文件 debug

我还在我的 POM 中添加了以下 Maven 配置文件:

<profile>
<id>debug</id>
<properties>
<additionalExecArgs>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address}</additionalExecArgs>
</properties>
</profile>

通过此配置,我可以简单地从项目上下文菜单/工具栏运行调试操作。

但是请注意 jpda.address Maven 属性。该属性似乎由 NetBeans 以某种方式填充。

如果我尝试在 IntelliJ 或 Eclipse 中使用调试配置文件运行 exec:exec ,则会收到错误,可能是因为 jpda.address Maven 属性未设置。

例如我在 IntelliJ 中收到以下错误:

/usr/lib/jvm/java-8-oracle/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:42300,suspend=y,server=n -Dmaven.home=/usr/share/maven -Dclassworlds.conf=/usr/share/maven/bin/m2.conf -Dfile.encoding=UTF-8 -classpath /usr/share/maven/boot/plexus-classworlds-2.x.jar:/opt/idea-IC-141.1010.3/lib/idea_rt.jar org.codehaus.classworlds.Launcher -Didea.version=14.1.3 -Dmaven.repo.local=/home/someUser/.m2/repository exec:exec -P debug
Connected to the target VM, address: '127.0.0.1:42300', transport: 'socket'
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test-application 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- exec-maven-plugin:1.4.0:exec (default-cli) @ test-application ---
ERROR: transport error 202: connect failed: Verbindungsaufbau abgelehnt
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

端口随着每次调用而变化。

我尝试将 jpda.address 替换为固定地址/端口(例如 127.0.0.1:8000),但现在在 NetBeans 中也遇到了相同的错误。

那么如何在 IntelliJ 和 Eclipse 中获得与 NetBeans 中类似的行为,并直接使用 Maven 运行配置调试 exec:exec 目标,而不必求助于远程调试器配置等?

最佳答案

听起来您可以使用启动前 Maven 目标在 intellij 中设置远程调试配置。

设置如下:

运行/调试配置 -> 添加远程 -> 添加启动前 -> Maven -> 指定正确的模块和目标。

关于java - IntelliJ 和 Eclipse : debug Java application started by Maven exec:exec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30518420/

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