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