Source:
public static void main(final String[] args) { String serviceAccountEmailAddress = args[0]; String serviceAccountKey = null; try { serviceAccountKey = Files.toString(new File(args[1]), Charset.defaultCharset()); } catch (IOException e) { System.err.println("Cannot open service account private key PEM file: " + args[1] + "\n" + e.getMessage()); System.exit(1); } String instanceName = args[2]; String zone = args[3]; String userName = System.getProperty("user.name"); String sshPrivateKeyFileName = System.getProperty("user.home") + "/.ssh/google_compute_engine"; String sshPrivateKey = null; try { sshPrivateKey = Files.toString(new File(sshPrivateKeyFileName), Charset.defaultCharset()); } catch (IOException e) { System.err.println("Cannot open your SSH private key at " + sshPrivateKeyFileName + "\nIt is required to perform any operations on your machine via SSH.\n" + "See <LINK_0> for more details.\n" + e.getMessage()); System.exit(1); } ExecuteCommand executeApplication = new ExecuteCommand(serviceAccountEmailAddress, serviceAccountKey); try { NodeMetadata instance = executeApplication.locateInstance(instanceName, zone); if (instance != null) { String publicAddress = instance.getPublicAddresses().iterator().next(); System.out.format("Instance %s found with IP %s%n", instance.getName(), publicAddress); } else { System.err.format("Error: Instance %s could not be located in zone %s.%n", instanceName, zone); System.exit(1); } executeApplication.executeSimpleCommand(instance, userName, sshPrivateKey); } catch (Exception e) { e.printStackTrace(); } finally { try { executeApplication.close(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } }

Target:
public static void main(final String[] args) { String serviceAccountEmailAddress = args[0]; String serviceAccountKey = null; try { serviceAccountKey = Files.toString(new File(args[1]), Charset.defaultCharset()); } catch (IOException e) { System.err.println("Cannot open service account private key PEM file: " + args[1] + "\n" + e.getMessage()); System.exit(1); } String instanceName = args[2]; String zone = args[3]; String userName = System.getProperty("user.name"); String sshPrivateKeyFileName = System.getProperty("user.home") + File.separator + ".ssh" + File.separator + "google_compute_engine"; String sshPrivateKey = null; try { sshPrivateKey = Files.toString(new File(sshPrivateKeyFileName), Charset.defaultCharset()); } catch (IOException e) { System.err.println("Unable to load your SSH private key at " + sshPrivateKeyFileName + "\nIt is required to perform any operations on your machine via SSH.\n" + "See <LINK_0> for more details.\n" + e.getMessage()); System.exit(1); } ExecuteCommand executeApplication = new ExecuteCommand(serviceAccountEmailAddress, serviceAccountKey); try { NodeMetadata instance = executeApplication.locateInstance(instanceName, zone); if (instance != null) { String publicAddress = instance.getPublicAddresses().iterator().next(); System.out.format("Instance %s found with IP %s%n", instance.getName(), publicAddress); } else { System.err.format("Error: Instance %s could not be located in zone %s.%n", instanceName, zone); System.exit(1); } executeApplication.executeSimpleCommand(instance, userName, sshPrivateKey); } catch (Exception e) { e.printStackTrace(); } finally { try { executeApplication.close(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } }