提交 d28db754 authored 作者: Thomas Mueller's avatar Thomas Mueller

H2 Console: the browser system property now supports a list of arguments.

上级 1abde6ed
...@@ -108,6 +108,8 @@ public class SysProperties { ...@@ -108,6 +108,8 @@ public class SysProperties {
* System property <code>h2.browser</code> (default: null).<br /> * System property <code>h2.browser</code> (default: null).<br />
* The preferred browser to use. If not set, the default browser is used. * The preferred browser to use. If not set, the default browser is used.
* For Windows, to use the Internet Explorer, set this property to 'explorer'. * For Windows, to use the Internet Explorer, set this property to 'explorer'.
* For Mac OS, if the default browser is not Safari and you want to use Safari,
* use: <code>java -Dh2.browser="open,-a,Safari,%url" ...</code>.
*/ */
public static final String BROWSER = getStringSetting("h2.browser", null); public static final String BROWSER = getStringSetting("h2.browser", null);
......
...@@ -31,7 +31,13 @@ public class StartBrowser { ...@@ -31,7 +31,13 @@ public class StartBrowser {
try { try {
String browser = SysProperties.BROWSER; String browser = SysProperties.BROWSER;
if (browser != null) { if (browser != null) {
if (osName.indexOf("windows") >= 0) { if (browser.indexOf("%url") >= 0) {
String[] args = StringUtils.arraySplit(browser, ',', false);
for (int i = 0; i < args.length; i++) {
args[i] = StringUtils.replaceAll(args[i], "%url", url);
}
rt.exec(args);
} else if (osName.indexOf("windows") >= 0) {
rt.exec(new String[] { "cmd.exe", "/C", browser, url }); rt.exec(new String[] { "cmd.exe", "/C", browser, url });
} else { } else {
rt.exec(new String[] { browser, url }); rt.exec(new String[] { browser, url });
...@@ -62,6 +68,7 @@ public class StartBrowser { ...@@ -62,6 +68,7 @@ public class StartBrowser {
if (osName.indexOf("windows") >= 0) { if (osName.indexOf("windows") >= 0) {
rt.exec(new String[] { "rundll32", "url.dll,FileProtocolHandler", url }); rt.exec(new String[] { "rundll32", "url.dll,FileProtocolHandler", url });
} else if (osName.indexOf("mac") >= 0) { } else if (osName.indexOf("mac") >= 0) {
// Mac OS: to open a page with Safari, use "open -a Safari"
Runtime.getRuntime().exec(new String[] { "open", url }); Runtime.getRuntime().exec(new String[] { "open", url });
} else { } else {
String[] browsers = { "firefox", "mozilla-firefox", "mozilla", "konqueror", "netscape", "opera" }; String[] browsers = { "firefox", "mozilla-firefox", "mozilla", "konqueror", "netscape", "opera" };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论