Java 在不丢失 MAVEN_OPTS 变量的情况下调试 maven

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3818481/
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-08-14 05:25:54  来源:igfitidea点击:

Debugging maven without losing MAVEN_OPTS variable

javamaven-2maven

提问by robinmag

rI want to run jetty:run in debug mode with MAVEN_OPTS setted in environment variable. But it seams like hardcode MAVEN_OPTS. Is it possible to set MAVEN_OPTS in command line like mvn MAVEN_OPTS=...

r我想在调试模式下运行 jetty:run 并在环境变量中设置 MAVEN_OPTS。但它看起来像硬编码 MAVEN_OPTS。是否可以在命令行中设置 MAVEN_OPTS 像mvn MAVEN_OPTS=...

Thank you.

谢谢你。

采纳答案by Pascal Thivent

Is it possible to set MAVEN_OPTS in command line like mvn MAVEN_OPTS=...

是否可以在命令行中设置 MAVEN_OPTS,如 mvn MAVEN_OPTS=...

No, MAVEN_OPTS is an environment variable, you can't set it on the command line. But you there is an alternative. Instead of mvn, you can simply run mvnDebug(a little variation of the former script that set debug options):

不,MAVEN_OPTS 是一个环境变量,你不能在命令行上设置它。但是你还有一个选择。而不是mvn,您可以简单地运行mvnDebug(设置调试选项的前一个脚本的一些变体):

$ mvnDebug jetty:run
Preparing to Execute Maven in Debug Mode
Listening for transport dt_socket at address: 8000

I find this alternative pretty handy, and easier.

我发现这个替代方案非常方便,也更容易。

回答by Andy

I encountered this problem, and my solution was to create a .bat file to set the maven opts, and then start jetty.

我遇到了这个问题,我的解决方法是创建一个.bat文件来设置maven opts,然后启动jetty。

call set MAVEN_OPTS=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8484,server=y,suspend=n %MAVEN_OPTS%
call mvn jetty:run-war -DskipTests=true

My IDE of choice is Eclipse, so I use the run button with the tool box to call the .bat files. Here is a question on running a .bat file.

我选择的 IDE 是 Eclipse,所以我使用带有工具箱的运行按钮来调用 .bat 文件。这是一个关于运行 .bat 文件的问题。

回答by Henryk Konsek

Under Windows - I don't know. Under Linux/Bash - yes you can:

在 Windows 下 - 我不知道。在 Linux/Bash 下 - 是的,您可以:

export MAVEN_OPTS="-Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" mvn jetty:run

回答by rharter

Under Windows you should be able to do the following from the command prompt:

在 Windows 下,您应该能够从命令提示符执行以下操作:

set MAVEN_OPTS=<options you want to add> %MAVEN_OPTS%
mvn jetty:run

Under Mac/Linux/Unix you can use export from the Terminal:

在 Mac/Linux/Unix 下,您可以使用从终端导出:

export MAVEN_OPTS=<options you want to add> $MAVEN_OPTS
mvn jetty:run

Not sure about how to do single use exports in Windows, but on Unix like operating systems you can just prepend the variable to your command (this works for any environment variable you want to add).

不确定如何在 Windows 中进行一次性导出,但在类似 Unix 的操作系统上,您可以将变量添加到您的命令中(这适用于您想要添加的任何环境变量)。

MAVEN_OPTS="option1 option2" mvn jetty:run