在Netbeans / Maven中远程调试单元测试 [英] Remotely debug unit tests in Netbeans / Maven
问题描述
我想使用Netbeans在Maven项目中的远程计算机上自动启动和调试单元测试。所有IDE功能都应该可以工作,例如调试,输出窗口等。只需单击调试聚焦测试方法,该过程就必须完全自动化。
I would like to automatically launch and debug unit tests on a remote machine in a Maven project using Netbeans. 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."
推荐答案
解决方案是用自定义脚本替换 mvn
命令,该脚本将执行 rsync
和 ssh
。通过这两种工具的神奇之处,它可以很好地实现 。此外,它应该可以移植到其他Maven IDE。当前指南适用于 bash
,但同样的想法可以在Windows中使用 powershell
实现, groovy
,甚至 cmd
。 (我尝试使用Nashorn,但是在正确保留所有参数的同时执行其他命令的方式似乎已经破解。)
The solution is to replace the mvn
command with a custom script which will perform an rsync
and an ssh
. Through the magic of both tools, it works really well. Also, it should be portable to other Maven IDEs. The current guide is for bash
, but the same idea could be implemented in Windows with powershell
, groovy
, or even cmd
. (I tried to use Nashorn, but the way to execute other commands while properly preserving all the arguments seemed broken.)
- 在Netbeans目录中
/usr/local/netbeans-8.1/java/maven/bin /
,重命名mvn
脚本:
-
cd /usr/local/netbeans-8.1/java/maven/bin /
-
sudo mv mvn mvn.orig
- In Netbeans directory
/usr/local/netbeans-8.1/java/maven/bin/
, rename themvn
script:cd /usr/local/netbeans-8.1/java/maven/bin/
sudo mv mvn mvn.orig
创建新
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
,或安装Netbeans并将其mvn
放在路径上。我选择了后者,但要么应该没问题。 - 配置ssh。我不会在这里描述如何做到这一点。确保
AllowTcpForwarding
设置为是
或远程
in/ etc / ssh / sshd_config
。
- 安装
- Configure the remote machine:
- Either install
mvn
, or install Netbeans and put itsmvn
on the path. I chose the later, but either should be fine. - Configure ssh. I won't describe how to do it here. Make sure that
AllowTcpForwarding
is set toyes
orremote
in/etc/ssh/sshd_config
. - 进入项目属性
- 创建新配置
-
在设置属性中添加:
- Go into Project's properties
- Create new Configuration
In "Set properties" add:
创建新的Netbeans配置将所有maven操作(包括clean& build)转发到远程计算机:
Create new Netbeans configuration that will forward all maven actions (including clean & build) to the remote machine:
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>
要使用,请在工具栏的下拉菜单中选择新配置,并照常调用任何maven目标。
To use, select the new configuration in the drop-down menu in the toolbar, and invoke any maven goal as usual.
这篇关于在Netbeans / Maven中远程调试单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- Either install
-