chat/server/src/main/java/org/apidesign/bck2brwsr/demo/chatserver/impl/Main.java
author Jaroslav Tulach <jtulach@netbeans.org>
Mon, 13 Jan 2014 08:49:24 +0100
branchNbHtml4J
changeset 58 7036237a58cb
parent 13 fd9a16bbfd0e
permissions -rw-r--r--
Also start the browser
jtulach@13
     1
/**
jtulach@13
     2
 * The MIT License (MIT)
jtulach@13
     3
 *
jtulach@13
     4
 * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jtulach@13
     5
 *
jtulach@13
     6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
jtulach@13
     7
 * of this software and associated documentation files (the "Software"), to deal
jtulach@13
     8
 * in the Software without restriction, including without limitation the rights
jtulach@13
     9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jtulach@13
    10
 * copies of the Software, and to permit persons to whom the Software is
jtulach@13
    11
 * furnished to do so, subject to the following conditions:
jtulach@13
    12
 *
jtulach@13
    13
 * The above copyright notice and this permission notice shall be included in
jtulach@13
    14
 * all copies or substantial portions of the Software.
jtulach@13
    15
 *
jtulach@13
    16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jtulach@13
    17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jtulach@13
    18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jtulach@13
    19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jtulach@13
    20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jtulach@13
    21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jtulach@13
    22
 * THE SOFTWARE.
jtulach@13
    23
 */
jtulach@13
    24
package org.apidesign.bck2brwsr.demo.chatserver.impl;
jtulach@13
    25
jtulach@58
    26
import java.awt.Desktop;
jtulach@58
    27
import java.io.IOException;
jtulach@13
    28
import java.net.URI;
jtulach@13
    29
import org.glassfish.grizzly.http.server.HttpServer;
jtulach@13
    30
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
jtulach@13
    31
import org.glassfish.jersey.server.ResourceConfig;
jtulach@13
    32
jtulach@13
    33
/** Starts chat server based on Jersey.
jtulach@13
    34
 *
jtulach@13
    35
 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jtulach@13
    36
 */
jtulach@13
    37
final class Main {
jtulach@13
    38
    public static void main(String... args) throws Exception {
jtulach@13
    39
        ResourceConfig rc = new ResourceConfig(
jtulach@13
    40
            ChatServerResource.class, ClientPagesResource.class
jtulach@13
    41
        );
jtulach@13
    42
        URI u = new URI("http://localhost:8080/");
jtulach@13
    43
        HttpServer server = GrizzlyHttpServerFactory.createHttpServer(u, rc);
jtulach@13
    44
        System.err.println("Server running at " + u);
jtulach@58
    45
        try {
jtulach@58
    46
            System.err.println("Launching browser");
jtulach@58
    47
            Desktop.getDesktop().browse(u);
jtulach@58
    48
        } catch (IOException ex) {
jtulach@58
    49
            System.err.println("Launching failed: " + ex.getMessage());
jtulach@58
    50
        }
jtulach@58
    51
        System.err.println("Press Enter to shutdown the server");
jtulach@13
    52
        System.in.read();
jtulach@13
    53
        server.stop();
jtulach@13
    54
    }
jtulach@13
    55
    
jtulach@13
    56
}