简体   繁体   English

使用mvnDebug命令在maven中进行调试

[英]Debugging in maven with mvnDebug command

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 谢谢

Wow, Maven makes this difficult. 哇,Maven让这很困难。 Setting -Xrunjdwp in MAVEN_OPTS won't work, because mvnDebug.bat adds its own afterward, which will override MAVEN_OPTS . MAVEN_OPTS设置-Xrunjdwp将不起作用,因为mvnDebug.bat后来添加了自己的,它将覆盖MAVEN_OPTS I would copy mvnDebug.bat to myMvnDebug.bat and comment out the line set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 . 我会将mvnDebug.bat复制到myMvnDebug.bat并注释掉行set MAVEN_DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 That way you can set MAVEN_DEBUG_OPT on the command line before running it. 这样,您可以在运行之前在命令行上设置MAVEN_DEBUG_OPT

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

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中,然后在调用mvnDebug xxx之前在env变量中设置MAVEN_DEBUG_PORT或在本地设置@set MAVEN_DEBUG_OPTS = 8001:run(我正在使用Jetty)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM