Performing remote Maven 3 builds with NetBeans 7.0

This article covers how to get NetBeans to use a Maven installation on a remote server. This has been tested with Maven 3.0.2 but should work on any other version. It may also work for other IDE’s like Eclipse if you can get them to use an alternate maven installation other than the internal one.

Sometimes you may want to run maven on a remote machine from inside the NetBeans IDE. For me this is down to available memory on the local machine is limited enough on large projects that both NetBeans and Maven compete slowing the local machine down as it swaps the IDE in and out of main memory.

Another instance may be to perform builds on a standard OS (Linux in this case) rather than the OS running the IDE (OSX here).

Now this is pretty easy to implement. Here I have the IDE running on OSX and the builds on Linux (Ubuntu 10.10) but if you can get the prerequisites running in theory any OS should work.


  • ssh access to both machines with public key authentication working
  • sshfs configured for mounting drives (you can use nfs or smb if you wish)
  • maven 3.0.2 installed on both machines – both machines need the same version

Setting up the environment

In this example:

  • sabrina – The local machine running NetBeans. It’s running OS X
  • kira – The remote machine which will run the builds. It’s running Ubuntu 10.10

Shared filesystems

The remote needs to have access to the local project directories for maven to work. As I have all development under a dev directory under home, on the remote machine I simply create a dev directory and then mount the local host from it using sshfs

<br />
peter@kira:~$ mkdir dev<br />
peter@kira:~$ sshfs peter@sabrina:dev dev<br />

If you have a custom settings.xml file, make sure it’s also present on the remote’s .m2 directory, i.e.

<br />
sabrina:~ peter$ scp .m2/settings.xml peter@kira:.m2<br />

Finally NetBeans needs access to the built artifacts, so to do this we mount the remotes .m2/repository locally. I use .m2/remoterepo for this

<br />
sabrina:~ peter$ mkdir .m2/remoterepo<br />
sabrina:~ peter$ sshfs peter@kira:.m2/repository .m2/remoterepo<br />


Next install your maven installation on both machines. I keep mine in the same place, but thats optional. For the purposes of this article I’m going to use /usr/local/apache/apache-maven-3.0.2

Next on the machine running NetBeans you need to create a duplicate installation /usr/local/apache/apache-maven-3.0.2-remote We need to have a copy for NetBeans to recognise it as a valid environment later on.

Now in this new installation we need to replace the /usr/local/apache/apache-maven-3.0.2-remote/bin/mvn script with the following:

<br />
#!/bin/bash<br />
#<br />
# Enable NetBeans 7.0 beta to run maven on a remote host</p>
<p># Pass the maven args as is<br />
<p># The current directory, NetBeans does a cd so this will be the project<br />
# directory.<br />
#<br />
# If you need to translate the path between local and remote machines then<br />
# pass the output of pwd through sed first<br />
<p># Execute maven on remote host<br />
REMOTE_USER=peter<br />
<p># Location of remote maven installation<br />
<p># JAVA_HOME on remote machine<br />
<p># ======================================<br />
# ======================================</p>
<p># Remote mvn command<br />
<p># Build the commands to run remotely<br />
CMD=&quot;cd ${REMOTE_PROJECT_DIR};&quot;<br />
CMD=&quot;${CMD}export JAVA_HOME=${REMOTE_JAVA_HOME};&quot;<br />
CMD=&quot;${CMD}$REMOTE_MVN ${MVN_ARGS}&quot;</p>
<p># Now run the remote build<br />
echo<br />
echo ------------------------------------------------------------------------<br />
echo Executing remote build on $REMOTE_HOST as $REMOTE_USER<br />
echo Remote command: $CMD<br />
echo ------------------------------------------------------------------------<br />
echo<br />
exec ssh ${REMOTE_USER}@${REMOTE_HOST} &quot;${CMD}&quot;<br />

In this script you need to ensure that the settings are correct:

  • REMOTE_USER and REMOTE_HOST point to your remote host,
  • REMOTE_MAVEN_HOME is the location of where maven is installed on the remote host,
  • REMOTE_JAVA_HOME is the location of the JDK on the remote host.

Now you may need to alter the line defining REMOTE_PROJECT_DIR. Shown above it gets set to the directory containing the maven project on the local host. If this differs on the remote then you need to either change to translate this to the location on the remote.

For example I have my NetBeans projects under a directory called dev in my home directory. As this is OS X that becomes /Users/peter/dev however on Linux the path is /home/peter/dev

I get around this by on the remote simply creating a symlink for /Users pointing to /home but you could modify the script to do that for you.

Configuring NetBeans

The last step is getting NetBeans to use the new remote.

Start NetBeans and enter preferences Then the Miscellaneous tab and finally Maven:

  • Under Maven Home select Browse and select the dummy remote installation, in my case /usr/local/apache/apache-maven-3.0.2-remote
  • Under Local Repository select Browse and point it at .m2/remoterepo
  • Select OK

Now if you try to run any build you’ll now see it run on the remote machine and as far as NetBeans is concerned it’s running locally. For example in the NetBeans output window you should see something like the following:

<br />
cd /Users/peter/dev/misc/example; JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home /usr/local/apache/apache-maven-3.0.2-remote/bin/mvn --batch-mode --lax-checksums --fail-fast --no-plugin-updates --batch-mode clean</p>
<p>------------------------------------------------------------------------<br />
Executing remote build on as peter<br />
Remote command: cd /Users/peter/dev/misc/example;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/;/usr/local/apache/apache-maven-3.0.2/bin/mvn --batch-mode --lax-checksums --fail-fast --no-plugin-updates --batch-mode clean<br />
<p>Command line option -npu is deprecated and will be removed in future Maven versions.<br />
Scanning for projects...<br />
------------------------------------------------------------------------<br />
Reactor Build Order:<br />

Future invocations

Once setup, whenever you restart either machines you simply need to mount each others drives before starting NetBeans as all the rest should then be setup.

<br />
sabrina:~ peter$ sshfs peter@kira:.m2/repository .m2/remoterepo<br />
peter@kira:~$ sshfs peter@sabrina:dev dev<br />

Configure a VPN under Linux

Although NetworkManager on Ubuntu supports VPN’s, it doesn’t always work so this article describes how to setup a PPTP VPN under linux. Although it’s Ubuntu specific (this works with 9.10 and 10.04), this should work for most distributions.

What you need

You need to know:

  • The remote IP address of the vpn server
  • The remote network address range
  • A remote name to give to this connection
  • remote username and password

What we’ll use for this article:

  • remote Server Ip –
  • remote network address range –
  • remote Name – myvpn
  • name – peter
  • password – password


First you need to install pptpd:

peter@kira:~$ sudo apt-get install pptp-linux ppp pptpd


Now as root create/etc/ppp/peers/myvpn with the following content – replace the example values listed above with your ones:

peter@kira:~$ sudo vi /etc/ppp/peers/myvpn
pty "pptp --nolaunchpppd"
#logfd 2
ipparam myvpn
remotename myvpn
name peter

Next edit /etc/ppp/chap-secrets and add the following line:

peter@kira:~$ sudo vi /etc/ppp/chap-secrets
peter  myvpn  password *

Now edit (create if missing) /etc/ppp/ip-up.d/add-subnet with the following:

peter@kira:~$ sudo vi /etc/ppp/ip-up.d/add-subnet
if [ "$PPP_IPPARAM" = "myvpn" ]
    route add -net dev $PPP_IFACE

If you created the add-subnet script then:

peter@kira:~$ chmod +x /etc/ppp/ip-up.d/add-subnet

Running the VPN Connection

Now if you have configured everything correctly you’ll be able to start the vpn with

peter@kira:~$ sudo pon myvpn

To stop the vpn:

peter@kira:~$ sudo poff myvpn

If it does not work first time you can uncomment the three lines of /etc/ppp/peers/myvpn. When you do the pon command will not return but it will log what it’s doing.

You may also have to tweek the other parameters in that file so it’s specific to your vpn.

Name resolution

The above will get you up and running with the actual connection but does nothing with configuring dns.

What you can do is either:

  • Manually edit /etc/resolv.conf each time with the remote dns
  • Edit /etc/ppp/ip-up.d/add-subnet to edit resolv.conf when it connects
  • Add hosts directly into your local /etc/hosts file
  • Use a local bind nameserver to use the remote dns server

I actually use the latter with a local bind nameserver.

Configuring bind9 on Ubuntu 10.04

Some of the applications on Ubuntu 10.04 like Gwibber can fail if they don’t get responses quickly enough from a DNS so one solution is to run a local copy of Bind9.

This article covers how to install bind9 on Ubuntu 10.04 to act as a local dns server speeding up dns queries, configuring bind with your local network, adding slaves and how to use bind with remote servers over a vpn.

Some of the applications on Ubuntu 10.04 like Gwibber can fail if they don’t get responses quickly enough from a DNS so one solution is to run a local copy of Bind9 which will handle the requests locally. This will not only solve some of the problems but would also speed up dns lookups in general.

A simple installation

First you need to install bind:

peter@kira:~$ sudo apt-get update
peter@kira:~$ sudo apt-get install bind9 dnsutils

Configure local networking

Next you need to configure networking to always use your local bind. Now this depends on if you are using static IP’s or DHCP.

For static IP’s simply replace the dns server addresses with that of your server, either or it’s own IP address on your network.

For DHCP, you need to tell it to ignore the dns settings. To do this:

  1. right click the network icon in the tool bar and select Edit Connections
  2. select the interface you want to use the dns server like Auto eth0 and press Edit
  3. Select the IPv4 Settings tab and change the method from Automatic (DHCP) to Automatic (DHCP) addresses only.
  4. Apply everything and you should be set.

Common problems to look out for

The following are common problems you should be aware of before you setup bind9.

IPv4 or IPv6

Ubuntu comes with both IPv4 and IPv6 enabled, however if you are not using IPv6 – or quite probably your ISP is still not supporting it either you may notice bind is a bit slow. This is because it’s trying to do lookups using IPv6 first, timing out so it then uses IPv4 which works.

To fix this you need to turn off IPv6 within bind.

peter@kira:~$ sudo vi /etc/default/bind9

Find the line starting with OPTIONS= and add -4 to it. Here’s what mine looks like.

# run resolvconf?

# startup options for the server
OPTIONS="-4 -u bind"

Once you have done that, when you next start/restart bind9 it will use IPv4 only.

Installing bind9 with dnsmasq already installed

If you already have dnsmasq installed you must either uninstall it first or, if you want to keep it as your DHCP server, disable it’s DNS server first otherwise the installation will fail as both cannot use the same port.

Now with dnsmasq you can’t actually do this but you can trick it by getting it to run on a different port. Simply edit /etc/dnsmasq.conf and add the following line near the top of the file:


Once you have done that then restart dnsmasq then you’ll be able to install bind.

Next we’ll cover how to create zone files defining your local network

Enable Network Address Translation (NAT) on Linux

Enabling Network Address Translation on Linux is pretty simple. I use it to enable my local network to use a Mobile Broadband stick connected to an old laptop, but this will work for any interface, not just for Mobile Broadband.

Enabling Network Address Translation on Linux is pretty simple. I use it to enable my local network to use a Mobile Broadband stick connected to an old laptop, but this will work for any interface, not just for Mobile Broadband.

What I have is a simple bash script stored in root’s home directory. Then when I first connect to the net I run this script (as root) which configures NAT and the rest of the network can then access the net.

Note: The script only needs to be run once per reboot, and the net connection needs to be up when it’s run. However if the net connection is restarted, as long as the machine has not been rebooted, the Linux kernel keeps the settings.

Here’s the script:


iptables -t nat -A POSTROUTING -s $NET -o $INT -j MASQUERADE
iptables -A FORWARD -s $NET -o $INT -j ACCEPT
iptables -A FORWARD -d $NET -m state --state ESTABLISHED,RELATED -i $INT -j ACCEPT
echo 1 >/proc/sys/net/ipv4/ip_forward

echo "Network $NET is now natted over $INT"

For this to work on your local machine, you simply need to edit the first two lines:

  • INT= the network interface to run Network Address Translation. hso0 here is for the Option modem I’m using on this specific laptop, but it could easily be ppp0 etc.
  • NET= the local network you want to allow access to the NAT.

If you don’t know what to use for INT, simply run ifconfig both before and after you connect to the net using your broadband, and the additional interface is more than likely the port to use.

Turn your Mac into a Wifi Base Station

Some people like myself use mobile broadband for their internet connection, either because it’s the only option where they live or like me have had enough of BT (in the UK you usually still need BT for the physical line regardless of the ISP).

Now with the various dongles they work fine on the the local machine and for the local wired network its usually as simple as turning on Internet Sharing (for the 3 network you have to do things differently due to them using a special profile). The problem comes to when you want to share the connection via wifi – but don’t have a wifi router.

On Linux boxes some wifi chipsets support base station mode but things become complicated due to having to configure the card, the firmware etcetera… but what about on a Mac? All recent Mac’s have AirPort cards so can a Mac act as a base station?

To put it simply, yes and it’s supported as standard (I’m using OSX10.5.7). Not only that it can be enabled from a couple of extra clicks.

First open System Preferences and select Sharing:

Next Select (not check) Internet Sharing and make sure AirPort is turned on (I also have Ethernet enabled as well).

Now at this point when you turn on sharing the WiFi connection will be open to anyone – so it’s probably advisable to turn on encryption by Selecting AirPort Options:

That’s all there is to it. You simply turn it on by turning Internet Sharing on and pressing start.

ssh-askpass on OSX 10.5

I’ve been playing with NetBeans 6.7M3 and the latest Mercurial plugin and found that I couldn’t push to a remote repository via ssh. All netbeans would return was:

Mercurial Push
INFO Pushing To: ssh:// ...
ERROR Command failed:
Command: [/usr/local/bin/hg, outgoing, -v, --template=rev:{rev}\nauth:{author}\ndesc:{desc}\ndate:{date|hgdate}\nid:{node|short}\n\nendCS:\n, --repository, /Users/peter/dev/gameaccount/maven/ga4Partner, ssh://]
Output: [running ssh “hg -R hg/ga4Partner serve --stdio”, remote: ssh_askpass: exec(/usr/libexec/ssh-askpass): No such file or directory, remote: Host key verification failed., abort: no suitable response from remote hg!]
INFO: End of Mercurial Push

Here the remote server is trying to prompt for the login password but fails because OSX 10.5 does not have the ssk-askpass command.

After some searching on the net (ok Google who else) I found Mercurial Push from IntelliJ where someone had a similar position with IntelliJ. By creating the following script mercurial in NB6.7M3 works flawlessly:

sabrina:~ peter$ sudo vi /usr/libexec/ssh-askpass
#! /bin/sh  
# An SSH_ASKPASS command for MacOS X  
# Author: Joseph Mocker, Sun Microsystems  
# To use this script:  
#     setenv SSH_ASKPASS "macos-askpass"  
#     setenv DISPLAY ":0"  
DIALOG="display dialog \"$@\" default answer \"\" with title \"$TITLE\""  
DIALOG="$DIALOG with icon caution with hidden answer"  
result=`osascript -e 'tell application "Finder"' -e "activate"  -e "$DIALOG" -e 'end tell'`  
if [ "$result" = "" ]; then  
    exit 1  
    echo "$result" | sed -e 's/^text returned://' -e 's/, button returned:.*$//'  
    exit 0  

sabrina:~ peter$ sudo chmod +x /usr/libexec/ssh-askpass

Connecting to both local lan and 3’s 3G Dongle on the Mac

A problem reported elsewhere on the net with 3’s 3G Broadband dongles is that while you are connected to the net it disconnects you from your local lan preventing you from accessing both. I presume its to prevent people from sharing the broadband without using their dedicated router which they sell to connect the dongle direct to the lan.

Anyhow the main problem for me is that when using a VPN with the dongle, the Mac could connect to the remote network fine, but Windows or Linux running inside VMWare could not as the dongle broke the network. This was causing me problems as I need to access MSSQL on the odd occasion.

Anyhow I’ve managed to figure out a way to allow the local lan to be connected at the same time with the dongle. In fact it’s so simple it’s stupid and I’m surprised no one has documented this anywhere else online – at least I never found it and various forums I’ve seen this question on don’t have this solution.

The trick is:

  1. Connect to the net
  2. Open System Preferences and click on Network
  3. You should see 3Connect in the Location dropdown – if not make sure it’s visible
  4. On the left you should see the list of interfaces (Ethernet, Bluetooth etc) all greyed out.
  5. Click on the + at the bottom left corner of that list and a popup appears.
  6. Select Ethernet in the Interface dropdown then press Create
  7. Now if you use DHCP like I do thats it – DHCP will kick in within a few seconds.
  8. If you don’t use DHCP then simply configure the new interface with a local static IP.

That’s it – nice and simple. Your milage may vary with this, but at least it worked for me.

Here’s the screenshot where you can see Ethernet 2 connected and the Dongle (disconnected when I took this screenshot):