Search code examples
javawindowsjava-8tomcat7external-application

Applications/processes ran using Java 8 on Windows are not visible


This has been making me work overtime and I still don't have much clues. I have a web application that is locally installed (pseudo-desktop app) that does the following:

  1. Starts an SSH tunnel
    • directly runs ssh if on Mac OS X
    • uses PuTTy executable if on Windows
  2. Opens Firefox or Chrome configured to use Socks5 proxy using the tunnel (localhost:port) via Selenium webdrivers.

For 1: I have used both Runtime.getRuntime().exec(command); and Process proc = new ProcessBuilder(arguments).start();, and even gave Desktop dt = Desktop.getDesktop(); dt.open(f); a try. But nothing happens, no command prompt opens.

For 2: I have tried using both Firefox:

    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("network.proxy.type", 1);
    profile.setPreference("network.proxy.socks", "localhost");
    profile.setPreference("network.proxy.socks_port", 8088);
    driver = new FirefoxDriver(profile);

And Chrome:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=socks5://localhost:8088"));
    driver = new ChromeDriver(capabilities);

But similar to 1, no firefox or chrome windows open.

Note that this application works perfectly on Mac OS X Mavericks.

After several hours of debugging, I noticed that the processes are there. All the processes, from PuTTy, to Chrome, to Firefox. There were a lot of those already running in the background. The odd thing is that the user column of these processes is set to SYSTEM, while the normal browser sessions, for example, the user is set to "IT", which is my current Windows user account.

I have been trying to manually change the user in which these processes are invoked, but no luck so far.

So apparently, my application works in Windows as well, just not as I intended. All the processes, regardless if it's a command line script or a desktop application like firefox or chrome, they just don't appear but they run in the background under the user "SYSTEM". And I don't have any idea why. It sure doesn't look like it's supposed to be the default behavior. So if anyone have any idea, I'd really appreciate it.

Thanks.


Solution

  • Finally I was able to fix this! Thanks to this article (from a seemingly not related case):

    Most Windows services -- including those run with the option "Allow service to interact with desktop" in Windows XP and Vista -- do not have access to many of the computer's resources, including the console display. This may cause Automated GUI Tests to fail if you are running Apache Tomcat as a Windows Service and are doing any GUI testing. This is true at least for AWT and Abbot frameworks.

    This limitation can be resolved by not running Tomcat as a Windows Service, but instead through a "Scheduled Task" as an Application that runs at logon. There are several options for doing this, an example would be to run "$TOMCAT_HOME\bin\tomcat5.exe". When setting up the scheduled task in Windows Vista consider choosing the check-box for "Run with highest privileges" from the general tab, as this removes the need to always provide administrator privileges and may resolve other issues as well.

    What I did was to NOT run tomcat7 as a Windows service, but instead just directly execute C:\Program Files\Apache Software Foundation\Tomcat 7.0\bin\Tomcat7.exe and everything worked perfectly. I can simply just put this as a scheduled task so it can still start automatically (or perhaps just put it on startup).