[Q#25320890][A#25321015] How to launch chrome browser from java
https://stackoverflow.com/q/25320890
Is there any smart way to launch the chrome browser from a java class? I'm asking because I would like a smart way to launch an application that required a chrome browser on a machine that has internet explorer as a default browser and java 1.4.2 installed. thanks
Answer
https://stackoverflow.com/a/25321015
You can execute chrome.exe like this: Provided you know where Chrome is installed.
APIzation
try {
Process p = Runtime.getRuntime().exec("\"/Program Files (x86)/Google/Chrome/Application/chrome.exe\"");
p.waitFor();
System.out.println("Google Chrome launched!");
} catch (Exception e) {
e.printStackTrace();
}
package com.stackoverflow.api;
public class Human25321015 {
public static void launchBrowser(String executablePath) {
try {
Process p = Runtime.getRuntime().exec(executablePath);
p.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.stackoverflow.api;
/**
* How to launch chrome browser from java
*
* @author APIzator
* @see <a href="https://stackoverflow.com/a/25321015">https://stackoverflow.com/a/25321015</a>
*/
public class APIzator25321015 {
public static void launchBrowser() throws Exception {
try {
Process p = Runtime
.getRuntime()
.exec("\"/Program Files (x86)/Google/Chrome/Application/chrome.exe\"");
p.waitFor();
System.out.println("Google Chrome launched!");
} catch (Exception e) {
e.printStackTrace();
}
}
}