Thanks!
Another approach if you can stomach a dialog box is to do the following:
HttpServer server = ...
server.start();
JFrame f = new JFrame();
JOptionPane.showMessageDialog(f, "Select OK to stop the server");
server.stop(0);
System.exit(0);
I am thinking that we should convert the embedded examples to do that
so that they work OK on windows.
Paul.
On Apr 6, 2008, at 3:30 PM, William Brogden wrote:
>
> This looks promising! In Java 6 we have the java.io.Console object
> obtained from System with .console() method. I tried this for the
> lightweight server.
> --------------------
> public static void main(String[] args) throws IOException {
> Console console = System.console();
> if( console == null ){
> System.out.println("No console available - can't
> continue");
> System.exit(1);
> }
> System.out.println("try to start lightweight server");
> // Create the HttpHandler
> // Pass in the Jersey resource class
> HttpHandler handler = ContainerFactory.createContainer(
> HttpHandler.class,
> LookupResource.class);
>
> // Create the HTTP server using the HttpHandler
> final HttpServer server = HttpServer.create(
> new InetSocketAddress(9998),
> 0); // default backlog
> server.createContext("/", handler);
> server.setExecutor(null); // default Executor
> server.start();
> System.out.println("Server running");
> System.out.println("Visit: http://localhost:9998/matching/
> domain/word");
> System.out.print("Press return to stop:");
> try {
> String rslt = console.readLine();
> }catch( Throwable t ){
> System.out.println("Error " + t );
> System.exit(1);
> }
> System.out.println("Normal exit");
> }
> --------------------
> When started from a Command Prompt window this works!!
>
> However, note that when I started from UltraEdit by executing
> a Ant command, console was null. I found references to
> other IDEs not providing a Console instance also. Have not
> checked NetBeans yet.
>
> Bill
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>