Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Starting exernal Program to display pdf etc.
Starting exernal Program to display pdf etc. [message #105553] Thu, 28 February 2008 16:34 Go to next message
Christian Campo is currently offline Christian CampoFriend
Messages: 597
Registered: July 2009
Senior Member
Hi,

I am looking for a method in Equinox or RCP to start a program i.e. to display a PDF. The only thing so far I found is
the class Program in package org.eclipse.swt.program.

There you could do stuff like

import org.eclipse.swt.program.Program;

.....
Program.launch("c:yourdocs.pdf");
.....


And it will bring up Adobe Reader and display that PDF. However for some I don't want to create a depenency to SWT and
fail to see how starting an external program is related to SWT.

Is there any way outside of SWT and Jface to start an external application.


thanks

christian campo
Re: Starting exernal Program to display pdf etc. [message #105565 is a reply to message #105553] Thu, 28 February 2008 18:27 Go to previous messageGo to next message
Wayne Beaton is currently offline Wayne BeatonFriend
Messages: 554
Registered: December 2017
Senior Member
How about java.lang.Runtime.getRuntime().exec(...)?

It doesn't seem to work on Linux with just a file, but this doesn't work
from the command line either. There's probably some magic that tells a
Linux shell to open a file with the default programme, but I don't know
what it is.

I imagine that this isn't part of CDC-1.x (but could be wrong)

Wayne


On Thu, 2008-02-28 at 17:34 +0100, Christian Campo wrote:
> Hi,
>
> I am looking for a method in Equinox or RCP to start a program i.e. to display a PDF. The only thing so far I found is
> the class Program in package org.eclipse.swt.program.
>
> There you could do stuff like
>
> import org.eclipse.swt.program.Program;
>
> ....
> Program.launch("c:yourdocs.pdf");
> ....
>
>
> And it will bring up Adobe Reader and display that PDF. However for some I don't want to create a depenency to SWT and
> fail to see how starting an external program is related to SWT.
>
> Is there any way outside of SWT and Jface to start an external application.
>
>
> thanks
>
> christian campo
Re: Starting exernal Program to display pdf etc. [message #105660 is a reply to message #105565] Fri, 29 February 2008 13:31 Go to previous messageGo to next message
Christian Campo is currently offline Christian CampoFriend
Messages: 597
Registered: July 2009
Senior Member
Hi Wayne,

Your solution sounded radical simple to me. However running
Program.launch("your.pdf");
works while
Runtime.getRuntime().exec("your.pdf");
does not. Even on Windows XP.

Anyone has an idea ?

thanks
christian

Wayne Beaton schrieb:
> How about java.lang.Runtime.getRuntime().exec(...)?
>
> It doesn't seem to work on Linux with just a file, but this doesn't work
> from the command line either. There's probably some magic that tells a
> Linux shell to open a file with the default programme, but I don't know
> what it is.
>
> I imagine that this isn't part of CDC-1.x (but could be wrong)
>
> Wayne
>
>
> On Thu, 2008-02-28 at 17:34 +0100, Christian Campo wrote:
>> Hi,
>>
>> I am looking for a method in Equinox or RCP to start a program i.e. to display a PDF. The only thing so far I found is
>> the class Program in package org.eclipse.swt.program.
>>
>> There you could do stuff like
>>
>> import org.eclipse.swt.program.Program;
>>
>> ....
>> Program.launch("c:yourdocs.pdf");
>> ....
>>
>>
>> And it will bring up Adobe Reader and display that PDF. However for some I don't want to create a depenency to SWT and
>> fail to see how starting an external program is related to SWT.
>>
>> Is there any way outside of SWT and Jface to start an external application.
>>
>>
>> thanks
>>
>> christian campo
>
Re: Starting exernal Program to display pdf etc. [message #105696 is a reply to message #105660] Fri, 29 February 2008 17:47 Go to previous messageGo to next message
Marcel Austenfeld is currently offline Marcel AustenfeldFriend
Messages: 160
Registered: July 2009
Senior Member
You have to call this a bit different
Execute the program with a paramter.

...
...exec("C:/Program Files/Adobe/Acrobat 7.0/Reader/AcroRd32");

...exec("C:/Program Files/Adobe/Acrobat 7.0/Reader/AcroRd32 F:/Example.pdf");

Please read the Java API and this old but very good article for
more information.

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps. html?page=1

On Linux this will work also. If not, you can execute a native shell which again can execute a command.

I hope this helps
Re: Starting exernal Program to display pdf etc. [message #105767 is a reply to message #105696] Sun, 02 March 2008 15:32 Go to previous messageGo to next message
Christian Campo is currently offline Christian CampoFriend
Messages: 597
Registered: July 2009
Senior Member
Thanks Marcel,

however that is not quit the solution that I was looking for. Because then I need to query the registry
where the Acrobat Reader is or what other tool the user uses to display PDF.

Program.launch() accepts the datafile like "c:example.pdf" as parameter and let the OS figure out what
program to call to display it.

Runtime cannot do this. However it seems there is no alternative out of SWT for this problem. And I guess
it ended up being in SWT because they have complete different implementations for the different OS systems.

thanks anyway
christian


Marcel schrieb:
> You have to call this a bit different
> Execute the program with a paramter.
>
> ..
> ..exec("C:/Program Files/Adobe/Acrobat 7.0/Reader/AcroRd32");
>
> ..exec("C:/Program Files/Adobe/Acrobat 7.0/Reader/AcroRd32 F:/Example.pdf");
>
> Please read the Java API and this old but very good article for
> more information.
>
> http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps. html?page=1
>
> On Linux this will work also. If not, you can execute a native shell which again can execute a command.
>
> I hope this helps
Re: Starting exernal Program to display pdf etc. [message #105791 is a reply to message #105767] Mon, 03 March 2008 08:46 Go to previous message
Marcel Austenfeld is currently offline Marcel AustenfeldFriend
Messages: 160
Registered: July 2009
Senior Member
I've forgotten that since Java 1.6 there is a new method to do this identically to the swt class.
I think this could be what you need.

Api :

http://java.sun.com/javase/6/docs/api/java/awt/Desktop.html


Example:

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
File file;

if (Desktop.isDesktopSupported()) {
try {
file = new File("C:\\yourPdf.pdf");
Desktop desktop = Desktop.getDesktop();
desktop.open(file);
} catch (IOException e) {
}

}

I hope this is the right tip!
Previous Topic:When to use Application with Equinox
Next Topic:Classloader pollution
Goto Forum:
  


Current Time: Fri Mar 29 05:52:58 GMT 2024

Powered by FUDForum. Page generated in 0.04864 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top