java 使用 mvnDebug 命令在 maven 中调试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29310760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 15:01:53  来源:igfitidea点击:

Debugging in maven with mvnDebug command

javamavenintellij-ideatomcat7

提问by Tai

I read this: Debugging in Maven?

我读到: 在 Maven 中调试?

I'm running intellij remote debug and maven for a service I'm trying to debug.

我正在为我试图调试的服务运行 intellij 远程调试和 maven。

I'm running

我在跑

mvnDebug tomcat7:run 

Which gives me the following result

这给了我以下结果

Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000
^Ctai-m:sb-api-internal-server tai$ m

My problem is that I want to change the port easily. I know that I can go into the pom.xml file and change it or that I can do the following in:

我的问题是我想轻松更改端口。我知道我可以进入 pom.xml 文件并更改它,或者我可以执行以下操作:

mvnDebug.bat

mvnDebug.bat

@REM set MAVEN_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000

but I want to be able to specify my port on the command line. Is there any way to do this? I want to be able to debug multiple services on different addresses running at once and am under the impression that it would be a hassle to have to set and reset the debug file setting for each one.

但我希望能够在命令行上指定我的端口。有没有办法做到这一点?我希望能够在一次运行的不同地址上调试多个服务,并且我的印象是必须为每个服务设置和重置调试文件设置会很麻烦。

A friend said it should be possible but I can't seem to find a solution.

一位朋友说应该可以,但我似乎找不到解决方案。

Essentially Im looking for a way to easily switch the port a service is running on hopefully without modifying a file multiple times as I launch multiple services. Otherwise Is there another solution you can thing of? Ex having the first debug instance running on one port and then having the second on another (hard coded)?

本质上,我正在寻找一种方法来轻松切换服务正在运行的端口,希望在启动多个服务时不会多次修改文件。否则还有其他解决方案吗?Ex 在一个端口上运行第一个调试实例,然后在另一个端口上运行第二个(硬编码)?

Thanks

谢谢

采纳答案by Kevin Condon

Wow, Maven makes this difficult. Setting -Xrunjdwpin MAVEN_OPTSwon't work, because mvnDebug.batadds its own afterward, which will override MAVEN_OPTS. I would copy mvnDebug.batto myMvnDebug.batand comment out the line set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000. That way you can set MAVEN_DEBUG_OPTon the command line before running it.

哇,Maven 使这变得困难。设置-XrunjdwpinMAVEN_OPTS不起作用,因为mvnDebug.bat之后添加了自己的,这将覆盖MAVEN_OPTS. 我会复制mvnDebug.batmyMvnDebug.bat和注释掉线set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000。这样您就可以MAVEN_DEBUG_OPT在运行之前在命令行上进行设置。

C:\somewhere>set MAVEN_DEBUG_OPT=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8001
C:\somewhere>myMvnDebug.bat

回答by Neal Bamford

I changed @set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000

我改变了@set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000

to

@set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%MAVEN_DEBUG_PORT%

@set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%MAVEN_DEBUG_PORT%

in mvnDebug.cmd then either set MAVEN_DEBUG_PORT in env variables or locally with set @set MAVEN_DEBUG_OPTS=8001 before you call mvnDebug xxx:run (I'm using Jetty)

在 mvnDebug.cmd 然后要么在环境变量中设置 MAVEN_DEBUG_PORT 要么在本地使用 set @set MAVEN_DEBUG_OPTS=8001 调用 mvnDebug xxx:run (我正在使用 Jetty)