Java - Desktop.getDesktop().browse(URI) is supported, but does not open document (a citrix problem?)
Asked Answered
C

5

6

(I am not sure if this is the correct place to ask this question. Please move to suitable site)

I have a problem that is shown in below code. It does not work on machine (windows 2008) that has CITRIX Xen App 6-. There is no error, just that browser does not get launched. On my desktop (a windows7 box), it works.

package trials;

import java.awt.*;
import java.io.File;
import java.io.IOException;


public class Launch {

    public static void main(String[] args) throws IOException {
        if (args.length < 1) {
            System.out.println("argument filepath expected");
            return;
        }

        final boolean browseSupported = Desktop.getDesktop().isSupported(Desktop.Action.BROWSE);
        if ( !browseSupported) {
            System.out.println("Browse not supported");
            return;
        }

        final String filename = args[0];
        final File file = new File(filename);
        if (file.exists()) {
            Desktop.getDesktop().browse(file.toURI());
        } else {
            System.out.println(file.getAbsolutePath() + " does not exist");
        }
    }
}

I tried to use "open" as suggested in following answers. It did not work. The problem is narrowed down to 64bit version of Java(Oracle 1.6.0_25)

Catherincatherina answered 26/8, 2011 at 8:6 Comment(0)
G
2

I think the cause of this symptom is the awt package what uses a system call what the win2008 not supports. But it's a tip.

I think You should try an other solution for this:

if (file.exists()) {
        Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file.toURI());
    } else {
        System.out.println(file.getAbsolutePath() + " does not exist");
    }
Golden answered 31/8, 2011 at 10:31 Comment(2)
This doesn't work on non-Windows systems, so I'd recommend against using it.Lorindalorine
An actual code fix is not found, we used above work around , but used ProcessBuilder.Catherincatherina
N
5

To open a local file you have to use Desktop().open() not Desktop.browse()

Nolannolana answered 31/8, 2011 at 10:35 Comment(0)
B
3

Another easy possibility that I have tested on Windows XP:

org.eclipse.swt.program.Program.launch("file://" + filename);
Bobker answered 30/11, 2012 at 8:53 Comment(0)
G
2

I think the cause of this symptom is the awt package what uses a system call what the win2008 not supports. But it's a tip.

I think You should try an other solution for this:

if (file.exists()) {
        Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file.toURI());
    } else {
        System.out.println(file.getAbsolutePath() + " does not exist");
    }
Golden answered 31/8, 2011 at 10:31 Comment(2)
This doesn't work on non-Windows systems, so I'd recommend against using it.Lorindalorine
An actual code fix is not found, we used above work around , but used ProcessBuilder.Catherincatherina
L
1

Desktop.browse() launches the local web browser. On Windows, the web browser is probably kicking it out to the default shell, which opens the file.

My guess is that the browser on the Citrix system cannot/doesn't handle the file properly, thus not passing it to the shell.

In any case, it appears that if you are opening a file (and not a URL), then you want to use Destop.open() instead.

Lorindalorine answered 31/8, 2011 at 13:2 Comment(0)
O
0

I had a similar problem with the Desktop-class.

If the file will not open but throws an exception, try to edit it. I had trouble with some image files and windows, because there was no associated program but an editor.

Onceover answered 14/1, 2015 at 20:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.