提交 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;
import org.h2.util.Resources;
import java.io.IOException;
import java.io.PrintStream;
//## AWT end ##
import java.sql.SQLException;
......@@ -68,40 +69,112 @@ ShutdownHandler {
* The command line options are the same as in the Server tool,
* but this tool will always start the TCP, TCP and PG server.
* 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
*/
public static void main(String[] args) {
int exitCode = new Console().run(args);
int exitCode = new Console().run(args, System.out);
if (exitCode != 0) {
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");
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;
try {
web = Server.createWebServer(args);
web.setShutdownHandler(this);
web.start();
} catch (SQLException e) {
printProblem(e, web);
if (webStart) {
try {
web = Server.createWebServer(args);
web.setShutdownHandler(this);
web.start();
} catch (SQLException e) {
printProblem(e, web);
}
}
try {
tcp = Server.createTcpServer(args);
tcp.start();
} catch (SQLException e) {
printProblem(e, tcp);
if (tcpStart) {
try {
tcp = Server.createTcpServer(args);
tcp.start();
} catch (SQLException e) {
printProblem(e, tcp);
}
}
try {
pg = Server.createPgServer(args);
pg.start();
} catch (SQLException e) {
printProblem(e, pg);
if (pgStart) {
try {
pg = Server.createPgServer(args);
pg.start();
} catch (SQLException e) {
printProblem(e, pg);
}
}
//## AWT begin ##
if (!GraphicsEnvironment.isHeadless()) {
if (toolStart && !GraphicsEnvironment.isHeadless()) {
if (isWindows) {
font = new Font("Dialog", Font.PLAIN, 11);
} else {
......@@ -122,7 +195,9 @@ ShutdownHandler {
// start browser anyway (even if the server is already running)
// because some people don't look at the output,
// but are wondering why nothing happens
StartBrowser.openURL(web.getURL());
if (browserStart) {
StartBrowser.openURL(web.getURL());
}
if (!web.isRunning(true)) {
exitCode = EXIT_ERROR;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论