public static void main(String[] args) throws IOException {
        if (args.length != 3) {
            System.out.println("");
            System.out.println("Usage: COMMAND <http-listen-port> <app-info-file> <database-file>");
            System.out.println("");
            System.out.println(" <http-listen-port>: The port to run the HTTP server on.  For example,");
            System.out.println("    \"8080\").");
            System.out.println("");
            System.out.println(" <app-info-file>: A JSON file containing your Dropbox API app key, secret");
            System.out.println("    and access type.  For example, \"my-app.app\" with:");
            System.out.println("");
            System.out.println("    {");
            System.out.println("      \"key\": \"Your Dropbox app key...\",");
            System.out.println("      \"secret\": \"Your Dropbox app secret...\"");
            System.out.println("    }");
            System.out.println("");
            System.out.println(" <database-file>: Where you want this program to store its database.  For");
            System.out.println("    example, \"web-file-browser.db\".");
            System.out.println("");
            System.exit(1);
            return;
        }

        String argPort = args[0];
        String argAppInfo = args[1];
        String argDatabase = args[2];

        // Figure out what port to listen on.
        int port;
        try {
            port = Integer.parseInt(argPort);
            if (port < 1 || port > 65535) {
                System.err.println("Expecting <http-listen-port> to be a number from 1 to 65535.  Got: " + port + ".");
                System.exit(1); return;
            }
        } catch (NumberFormatException ex) {
            System.err.println("Expecting <http-listen-port> to be a number from 1 to 65535.  Got: " + jq(argPort) + ".");
            System.exit(1); return;
        }

        // Read app info file (contains app key and app secret)
        DbxAppInfo dbxAppInfo;
        try {
            dbxAppInfo = DbxAppInfo.Reader.readFromFile(argAppInfo);
        } catch (JsonReader.FileLoadException ex) {
            System.err.println("Error loading <app-info-file>: " + ex.getMessage());
            System.exit(1); return;
        }
        System.out.println("Loaded app info from " + jq(argAppInfo));

        File dbFile = new File(argDatabase);

        // Run server
        try {
            Main main = new Main(new PrintWriter(System.out, true), dbxAppInfo, dbFile);

            Server server = new Server(port);
            SessionHandler sessionHandler = new SessionHandler();
            sessionHandler.setServer(server);
            sessionHandler.setHandler(main);
            server.setHandler(sessionHandler);

            server.start();
            System.out.println("Server running: http://localhost:" + port + "/");

            server.join();
        } catch (Exception ex) {
            System.err.println("Error running server: " + ex.getMessage());
            System.exit(1);
        }
    }
public static void main ( String [ ] args ) throws IOException { if ( args . length != 3 ) { System . out . println ( "" ) ; System . out . println ( "Usage: COMMAND <http-listen-port> <app-info-file> <database-file>" ) ; System . out . println ( "" ) ; System . out . println ( " <http-listen-port>: The port to run the HTTP server on.  For example," ) ; System . out . println ( "    \"8080\")." ) ; System . out . println ( "" ) ; System . out . println ( " <app-info-file>: A JSON file containing your Dropbox API app key, secret" ) ; System . out . println ( "    and access type.  For example, \"my-app.app\" with:" ) ; System . out . println ( "" ) ; System . out . println ( "    {" ) ; System . out . println ( "      \"key\": \"Your Dropbox app key...\"," ) ; System . out . println ( "      \"secret\": \"Your Dropbox app secret...\"" ) ; System . out . println ( "    }" ) ; System . out . println ( "" ) ; System . out . println ( " <database-file>: Where you want this program to store its database.  For" ) ; System . out . println ( "    example, \"web-file-browser.db\"." ) ; System . out . println ( "" ) ; System . exit ( 1 ) ; return ; } String argPort = args [ 0 ] ; String argAppInfo = args [ 1 ] ; String argDatabase = args [ 2 ] ; int port ; try { port = Integer . parseInt ( argPort ) ; if ( port < 1 || port > 65535 ) { System . err . println ( "Expecting <http-listen-port> to be a number from 1 to 65535.  Got: " + port + "." ) ; System . exit ( 1 ) ; return ; } } catch ( NumberFormatException ex ) { System . err . println ( "Expecting <http-listen-port> to be a number from 1 to 65535.  Got: " + jq ( argPort ) + "." ) ; System . exit ( 1 ) ; return ; } DbxAppInfo dbxAppInfo ; try { dbxAppInfo = DbxAppInfo . Reader . readFromFile ( argAppInfo ) ; } catch ( JsonReader . FileLoadException ex ) { System . err . println ( "Error loading <app-info-file>: " + ex . getMessage ( ) ) ; System . exit ( 1 ) ; return ; } System . out . println ( "Loaded app info from " + jq ( argAppInfo ) ) ; File dbFile = new File ( argDatabase ) ; try { Main main = new Main ( new PrintWriter ( System . out , true ) , dbxAppInfo , dbFile ) ; Server server = new Server ( port ) ; SessionHandler sessionHandler = new SessionHandler ( ) ; sessionHandler . setServer ( server ) ; sessionHandler . setHandler ( main ) ; server . setHandler ( sessionHandler ) ; server . start ( ) ; System . out . println ( "Server running: http://localhost:" + port + "/" ) ; server . join ( ) ; } catch ( Exception ex ) { System . err . println ( "Error running server: " + ex . getMessage ( ) ) ; System . exit ( 1 ) ; } }
Parse command-line arguments and start server.