提交 7d80f3dc authored 作者: Thomas Mueller's avatar Thomas Mueller

The Console tool now supports command line options to start things separately.

上级 5658558a
...@@ -32,6 +32,7 @@ import java.awt.event.WindowEvent; ...@@ -32,6 +32,7 @@ import java.awt.event.WindowEvent;
import org.h2.util.Resources; import org.h2.util.Resources;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream;
//## AWT end ## //## AWT end ##
import java.sql.SQLException; import java.sql.SQLException;
...@@ -68,40 +69,112 @@ ShutdownHandler { ...@@ -68,40 +69,112 @@ ShutdownHandler {
* The command line options are the same as in the Server tool, * The command line options are the same as in the Server tool,
* but this tool will always start the TCP, TCP and PG server. * but this tool will always start the TCP, TCP and PG server.
* Options are case sensitive. * Options are case sensitive.
* *
* The command line interface for this tool. The options must be split into
* strings like this: "-baseDir", "/temp/data",... By default, -tcp, -web,
* -browser and -pg are started. If there is a problem starting a service,
* the program terminates with an exit code of 1. Options are case
* sensitive. The following options are supported:
* <ul>
* <li>-help or -? (print the list of options) </li>
* <li>-web (start the Web Server and H2 Console) </li>
* <li>-tool (start the icon or window that allows to start a browser)</li>
* <li>-browser (start a browser and open a page to connect to the
* Web Server) </li>
* <li>-tcp (start the TCP Server) </li>
* <li>-pg (start the PG Server) </li>
* </ul>
* For each Server, additional options are available.
* Those options are the same as in the Server tool.
*
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String[] args) { public static void main(String[] args) {
int exitCode = new Console().run(args); int exitCode = new Console().run(args, System.out);
if (exitCode != 0) { if (exitCode != 0) {
System.exit(exitCode); System.exit(exitCode);
} }
} }
private void showUsage(PrintStream out) {
out.println("Starts H2 Console");
out.println("By default, -web, -tool, -browser, -tcp, and -pg are started. Options are case sensitive.");
out.println("java "+getClass().getName());
out.println("-web Start the Web Server and H2 Console");
out.println("-tool Start the icon or window that allows to start a browser (includes -web)");
out.println("-browser Start a browser to connect to the H2 Console (includes -web)");
out.println("-tcp Start the TCP Server");
out.println("-pg Start the PG Server");
out.println("See also http://h2database.com/javadoc/" + getClass().getName().replace('.', '/') + ".html");
}
private int run(String[] args) { private int run(String[] args, PrintStream out) {
isWindows = SysProperties.getStringSetting("os.name", "").startsWith("Windows"); isWindows = SysProperties.getStringSetting("os.name", "").startsWith("Windows");
boolean tcpStart = false, pgStart = false, webStart = false, toolStart = false;
boolean browserStart = false;
boolean startDefaultServers = true;
for (int i = 0; args != null && i < args.length; i++) {
String arg = args[i];
if (arg == null) {
continue;
} else if ("-?".equals(arg) || "-help".equals(arg)) {
showUsage(out);
return EXIT_ERROR;
} else if ("-web".equals(arg)) {
startDefaultServers = false;
webStart = true;
} else if ("-tool".equals(arg)) {
startDefaultServers = false;
webStart = true;
toolStart = true;
} else if ("-browser".equals(arg)) {
startDefaultServers = false;
webStart = true;
browserStart = true;
} else if ("-tcp".equals(arg)) {
startDefaultServers = false;
tcpStart = true;
} else if ("-pg".equals(arg)) {
startDefaultServers = false;
pgStart = true;
}
}
if (startDefaultServers) {
webStart = true;
toolStart = true;
browserStart = true;
tcpStart = true;
pgStart = true;
}
int exitCode = 0; int exitCode = 0;
try { if (webStart) {
web = Server.createWebServer(args); try {
web.setShutdownHandler(this); web = Server.createWebServer(args);
web.start(); web.setShutdownHandler(this);
} catch (SQLException e) { web.start();
printProblem(e, web); } catch (SQLException e) {
printProblem(e, web);
}
} }
try { if (tcpStart) {
tcp = Server.createTcpServer(args); try {
tcp.start(); tcp = Server.createTcpServer(args);
} catch (SQLException e) { tcp.start();
printProblem(e, tcp); } catch (SQLException e) {
printProblem(e, tcp);
}
} }
try { if (pgStart) {
pg = Server.createPgServer(args); try {
pg.start(); pg = Server.createPgServer(args);
} catch (SQLException e) { pg.start();
printProblem(e, pg); } catch (SQLException e) {
printProblem(e, pg);
}
} }
//## AWT begin ## //## AWT begin ##
if (!GraphicsEnvironment.isHeadless()) { if (toolStart && !GraphicsEnvironment.isHeadless()) {
if (isWindows) { if (isWindows) {
font = new Font("Dialog", Font.PLAIN, 11); font = new Font("Dialog", Font.PLAIN, 11);
} else { } else {
...@@ -122,7 +195,9 @@ ShutdownHandler { ...@@ -122,7 +195,9 @@ ShutdownHandler {
// start browser anyway (even if the server is already running) // start browser anyway (even if the server is already running)
// because some people don't look at the output, // because some people don't look at the output,
// but are wondering why nothing happens // but are wondering why nothing happens
StartBrowser.openURL(web.getURL()); if (browserStart) {
StartBrowser.openURL(web.getURL());
}
if (!web.isRunning(true)) { if (!web.isRunning(true)) {
exitCode = EXIT_ERROR; exitCode = EXIT_ERROR;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论