public static void main(String[] args) throws Exception {
        if (args.length > 2 || args.length < 1) {
            System.err.println(HELP_TEXT);
            System.exit(-1);
        }

        ArchiveManager archiveManager = new ArchiveManager();
        WikiApp wikiApp = new WikiApp(archiveManager, true);

        if(wikiApp.getContext().getString("container_prefix", null) == null) {
            throw new RuntimeException("Assertion Failure: container_prefix not set!");
        }

        try {
            // Try to parse the argument as an integer listen port.
            wikiApp.setListenPort(Integer.parseInt(args[0]));

        } catch (NumberFormatException nfe) {
            File asFile = new File(args[0]);
            if (asFile.getName().equals(STATE_FILE)) {
                System.out.println("Using app state file: " + asFile.getAbsolutePath());
                archiveManager.setByteStore(new FileByteStore(asFile));
                try {
                    wikiApp.getContext().restoreAppState();
                    System.out.println("Loaded saved state.");
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                    System.out.println("Couldn't load saved state.");
                }
            } else {
                System.out.println("Reading expored configuration from: " + args[0]);
                Configuration config =
                    Configuration.fromStringRep(IOUtil.readUtf8StringAndClose(new FileInputStream(args[0])));
                wikiApp.getContext().setConfiguration(config);
            }
        }

        if (args.length == 1) {
            archiveManager.createEmptyArchive();
        } else {
            // Needs to happen after the config is loaded.
            archiveManager.load(args[1]);
        }

        int listenPort = wikiApp.getContext().getInt("listen_port", WikiApp.LISTEN_PORT);
        final String containerPrefix = wikiApp.getContext().getString("container_prefix", null);
        // Redirect non-routed requests to the wiki app.
        HTTPServer.ContextHandler defaultRedirect = new HTTPServer.ContextHandler() {
                public int serve(HTTPServer.Request req, HTTPServer.Response resp) throws IOException {
                    resp.redirect(containerPrefix, false);
                    return 0;
                }
            };

        HTTPServer server = new HTTPServer(listenPort);
        HTTPServer.VirtualHost host = server.getVirtualHost(null); // default host
        host.setAllowGeneratedIndex(false);
        host.setDirectoryIndex("/"); // Keep from sending default "index.html"
        host.addContext(containerPrefix, new FnikiContextHandler(wikiApp));
        host.addContext("/", defaultRedirect);
        server.start();

        System.err.println(String.format("Serving wiki on: http://127.0.0.1:%d%s",
                                         listenPort, containerPrefix));
    }