[英]Remotely debug unit tests in Netbeans / Maven
I would like to automatically launch and debug unit tests on a remote machine in a Maven project using Netbeans. 我想使用Netbeans在Maven项目中的远程机器上自动启动和调试单元测试。 All the IDE features should work, such as debugging, the output window, etc. The process has to be fully automated with a single click of "Debug Focused Test Method."
所有的IDE功能都应该起作用,例如调试,输出窗口等。必须通过单击“调试重点测试方法”完全自动化该过程。
The solution is to replace the mvn
command with a custom script which will perform an rsync
and an ssh
. 解决方案是将
mvn
命令替换为将执行rsync
和ssh
的自定义脚本。 Through the magic of both tools, it works really well. 通过这两种工具的魔力,它确实运行良好。 Also, it should be portable to other Maven IDEs.
而且,它应该可移植到其他Maven IDE。 The current guide is for
bash
, but the same idea could be implemented in Windows with powershell
, groovy
, or even cmd
. 当前指南是针对
bash
,但是相同的想法可以在Windows中使用powershell
, groovy
甚至cmd
。 (I tried to use Nashorn, but the way to execute other commands while properly preserving all the arguments seemed broken.) (我尝试使用Nashorn,但是在正确保留所有参数的同时执行其他命令的方法似乎已失效。)
/usr/local/netbeans-8.1/java/maven/bin/
, rename the mvn
script: /usr/local/netbeans-8.1/java/maven/bin/
,重命名mvn
脚本:
cd /usr/local/netbeans-8.1/java/maven/bin/
sudo mv mvn mvn.orig
Create new mvn
script. 创建新的
mvn
脚本。
#!/bin/bash if [ -z "$REMOTE" ] ; then SCRIPTDIR=$(dirname "$0") "$SCRIPTDIR/mvn.orig" "$@" else if [ -z "$REMOTE_BASE_DIR" ] ; then echo "ERROR: Please set environment variable REMOTE_BASE_DIR to the folder which contains the project directory" exit fi PROJECT_DIR=$(basename "$(pwd)") REMOTE_PROJECT_DIR=$REMOTE_BASE_DIR/$PROJECT_DIR/ ARGS= for var in "$@" do ARGS="$ARGS \\\\\\"$var\\\\\\"" done echo "Syncing project directory..." (set -x; rsync -aczhW --progress --delete --exclude '.git' --exclude 'target' $RSYNC_OPTS ./ "$REMOTE:\\"$REMOTE_PROJECT_DIR\\"") echo "Executing maven..." if [ "$REMOTE_PORT" = '${jpda.address}' ] ; then (set -x; ssh ${REMOTE} "cd \\"$REMOTE_PROJECT_DIR\\"; mvn $ARGS") else (set -x; ssh -R $REMOTE_PORT:localhost:$REMOTE_PORT ${REMOTE} "cd \\"$REMOTE_PROJECT_DIR\\"; mvn $ARGS") fi fi
mvn
, or install Netbeans and put its mvn
on the path. mvn
或安装Netbeans并将其mvn
放在路径上。 I chose the later, but either should be fine. AllowTcpForwarding
is set to yes
or remote
in /etc/ssh/sshd_config
. /etc/ssh/sshd_config
中将AllowTcpForwarding
设置为yes
或remote
。 Create new Netbeans configuration that will forward all maven actions (including clean & build) to the remote machine: 创建新的Netbeans配置,该配置会将所有Maven操作(包括清理和构建)转发到远程计算机:
In "Set properties" add: 在“设置属性”中添加:
Env.REMOTE_BASE_DIR=<directory on the server that will contain your project directory> Env.REMOTE=<address of remote machine> Env.REMOTE_PORT=${jpda.address} Env.RSYNC_OPTS=<optional, but could be another --exclude>
To use, select the new configuration in the drop-down menu in the toolbar, and invoke any maven goal as usual. 若要使用,请在工具栏的下拉菜单中选择新配置,然后照常调用任何Maven目标。
Surefire / Failsafe插件支持开箱即用的远程调试: http : //maven.apache.org/surefire/maven-surefire-plugin/examples/debugging.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.