Open Chrome in app-mode from Java Web Start not working

267 Views Asked by At

I'm trying to open a HTML page in Chrome using the --app cli option but I can't get it to work when I start my Java Swing application with Java Web Start.

When I run the command using CLI from CMD it works fine. I get a window without url, shortcuts and any other crap.

C:\Program Files\Google\Chrome\Application>Chrome.exe --app="http://www.google.com"

When I run my application from Eclipse it also works fine.

String url = "http://www.google.com";
Process p = Runtime.getRuntime().exec("\"C:/Program Files/Google/Chrome/Application/chrome.exe\" --app=\"" + url + "\"");

But when I build my .jar-files and sign them and deploy them using Java Web Start the page is opened in a Chrome-tab instead of a new window.

Does anyone have any idea why this is?

I thought it might have been related to the fact that I was starting my application using Chrome, so that my Chrome application became a parent in some way. But I've started my application from both Chrome and Edge and the result is the same, a new "tab" is opened in Chrome instead of a new window.

1

There are 1 best solutions below

0
Stefan Hagström On BEST ANSWER

I hate to say it, but ChatGPT helped me! I got it to work, but I still would like to understand what was causing the Runtime-problem.

The first solution ChatGPT suggested was

Desktop.getDesktop().browse(URI.create(chromePath + " " + appModeUrl));

But that couldn't handle the space in "Program Files" and in "chrome.exe --app" so when I clarified that in my question I got the answed below.

import java.io.IOException;

public class LaunchChromeInAppMode {

  public static void main(String[] args) {
    String url = "https://stackoverflow.com/";
    String chromePath = "C:/Program Files/Google/Chrome/Application/chrome.exe";
    String appModeFlag = "--app=";
    String appModeUrl = appModeFlag + url;

    try {
      ProcessBuilder processBuilder = new ProcessBuilder(chromePath, appModeUrl);
      Process process = processBuilder.start();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}