public void connect()
            throws P4JavaException, URISyntaxException, IOException {
        InputStream is = null;
        try {
            String propertiesFile = System.getProperty(PROPERTIES_FILE_KEY);
            if (propertiesFile == null) {
                is = this.getClass().getResourceAsStream(PROPERTIES_FILE);
            } else {
                File propFile = new File(propertiesFile);
                if (!propFile.exists()) {
                    throw new FileNotFoundException(String.format("Key: %s File: %s not found.", PROPERTIES_FILE_KEY, propertiesFile));
                }
                is = new FileInputStream(propFile);
            }
            if (is != null) {
                Properties props = new Properties();
                props.load(is);
                String sName = props.getProperty("servername");
                server = ServerFactory.getOptionsServer(sName, props);
                server.connect();
                server.addTrust(new TrustOptions().setAutoAccept(true));
                // First check the P4PASSWD environment variable
                String password = System.getenv().get(P4PASSWD);
                // if not there grab it from -D
                // if not there, try the properties file for the password
                if (password == null || password.isEmpty()) {
                    password = System.getProperty(P4PASSWD, props.getProperty(PropertyDefs.PASSWORD_KEY_SHORTFORM));
                }
                if (password != null && !password.isEmpty()) {
                    server.login(password);
                } else {
                    throw new IOException("no p4 password provided");
                }
            } else {
                throw new FileNotFoundException("Properties file was not found: " + PROPERTIES_FILE);
            }

        } finally {
            if (is != null) { try {is.close();} catch (Exception ignore) {} }
        }
    }