Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with Java 1.6 and Desktop.open()

I've been using Destop.open() to launch a .pdf viewer on Windows machines, both Vista and XP, and most of them work just fine. However, on one XP machine the call does not work, simply returning without throwing any exceptions, and the viewer does not launch. On that machine the file association is properly set up as far as I can tell: double-clicking a .pdf works, as does the "start xxx.pdf" command on the command prompt. I'm thinking it must be a Windows configuration issue, but can't put my finger on it.

Has anyone else seen this problem?

like image 570
Scott Avatar asked Sep 17 '08 15:09

Scott


2 Answers

This is a known problem with early versions of XP SP2, the ShellExecute function stopped accepting URIs; bring the XP machines patches up to date.

To view the exceptions make sure the Java Console is turned on:

Control Panel->Java Control Panel->Advanced->Java Console.
like image 190
Martin Spamer Avatar answered Oct 16 '22 20:10

Martin Spamer


I couldn't find the answer anywhere but I have two machines with Windows 7 64 bit that fail the Desktop.getDesktop().open(file) with failed to open file or access is denied error on java 6 and java 7.

Windows Explorer is able to open applications based on the filename with extension:

Runtime rt = Runtime.getRuntime();
rt.exec(new String[]{"explorer", "C:\\myfile.pdf"});
rt.exec(new String[]{"explorer", "C:\\myfile.wmv"});
like image 38
Lund Wolfe Avatar answered Oct 16 '22 19:10

Lund Wolfe