code: function findPort(cb) {
      var port = tryPort;
      tryPort += 1;
  
      var server = net.createServer();
      server.listen(port, function(err) {
          server.once('close', function() {
              cb(port);
          });
          server.close();
      });
      server.on('error', function(err) {
          log("port " + tryPort + " is occupied");
          findPort(cb);
      });
  }
docs: get an empty port for the java server