Java 从终端以调试模式运行 jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52947783/
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
run jar in debug mode from terminal
提问by Pawel
I'm using intellij idea IDE and I'm trying to run my jar file from terminal in debug mode and set breakpoints in a few places in the code.
我正在使用 intellij idea IDE,我试图在调试模式下从终端运行我的 jar 文件,并在代码中的几个地方设置断点。
the command I'm using is: java -jar myTestApp.jar -file "myfile.txt" -users myUser -Xdebug -Xrunjdwp:transport=dt_socket,server=127.0.0.1,suspend=n,address=8080
我使用的命令是: java -jar myTestApp.jar -file "myfile.txt" -users myUser -Xdebug -Xrunjdwp:transport=dt_socket,server=127.0.0.1,suspend=n,address=8080
The problem is that I'm also using commons-cli library, so -Xdebug and -Xrunjdwp parameters are not recognized as Options, and I'm getting:Any idea how to fix that?
问题是我也在使用 commons-cli 库,所以 -Xdebug 和 -Xrunjdwp 参数不被识别为选项,我得到:知道如何解决这个问题吗?
采纳答案by SWiggels
Please assume the writer of the question is not using Java 5 in 2018:
请假设问题的作者在 2018 年没有使用 Java 5:
java -agentlib:jdwp=transport=dt_socket,address=8080,server=y,suspend=n -jar myTestApp.jar -file "myfile.txt -users myUser
java -agentlib:jdwp=transport=dt_socket,address=8080,server=y,suspend=n -jar myTestApp.jar -file "myfile.txt -users myUser
Btw: in case you use Java 9 and later: change address=8080
to address=*:8080
since localhost is no more the default.
顺便说一句:如果您使用Java 9 及更高版本:更改address=8080
为address=*:8080
因为 localhost 不再是默认值。
stop telling people to use -Xdebug
and -Xrunjdwp
停止告诉人们使用-Xdebug
和-Xrunjdwp
Xdebugwas used in Java 5 and below. Since Java 6 there is the -agentlib
available.
Xdebug
allows access to the debugger over Xrunjdwp
. ?JIT now starts in a compatibility-mode if you use Xdebug
and uses a legacy-debugger which slows down your debugging extremely. ?People tell then to use -Djava.compiler=NONE
to disable the compatibility-mode or to add -Xnoagent
to disable the legacy debugger. Don't do that use -agentlib
!
Xdebug用于 Java 5 及以下版本。从 Java 6 开始就有了-agentlib
。
Xdebug
允许通过 访问调试器Xrunjdwp
。?JIT 现在以兼容模式启动,如果您使用Xdebug
并使用遗留调试器,这会极大地减慢您的调试速度。?人们告诉然后使用-Djava.compiler=NONE
禁用兼容模式或添加-Xnoagent
禁用遗留调试器。不要那样用-agentlib
!
回答by SurfMan
-Xdebug should be moved in front of the -jar parameter. Now Java thinks it's part of your program's arguments.
-Xdebug 应该移到 -jar 参数的前面。现在 Java 认为它是程序参数的一部分。
回答by Damarus
Java expects only program arguments after specifying the class or jar to run. So simply try putting your JVM options before that:
在指定要运行的类或 jar 之后,Java 只需要程序参数。因此,只需尝试在此之前放置您的 JVM 选项:
java -Xdebug -Xrunjdwp:transport=dt_socket,server=127.0.0.1,suspend=n,address=8080 -jar myTestApp.jar -file "myfile.txt" -users myUser
回答by Tabish Ahmed
this worked for me
这对我有用
java -jar -Xdebug -agentlib:jdwp="transport=dt_socket,server=y,suspend=n,address=5000" core-service-1.0-SNAPSHOT.jar