Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Open file from command line (Pure E4 RCP)
Open file from command line (Pure E4 RCP) [message #1021151] Tue, 19 March 2013 15:25 Go to next message
Severin Raevskiy is currently offline Severin RaevskiyFriend
Messages: 5
Registered: March 2013
Junior Member
Hello. I would like to open files passed as command line arguments in my pure E4 RCP application (Eclipse 4.2). So I am using this article http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html and and I am tring to rewrite everything in E4 style.

I have created a listener class
public class OpenKmlEventProcessor implements Listener
{
 @Override
 public void handleEvent(Event event)
 {
  if (event.text != null)
  {
   ...
  }
 }
}

and attached in to Display in @PostConstruct method of my Addon
@PostConstruct
void hookListeners(...)
{
 ...
 Display.getDefault().addListener(SWT.OpenDocument, openKmlProcessor);
}

In the same addon I am processing command line arguments
@Inject
void proccessCmdLineArguments(IApplicationContext appContext)
{
 ...
 String[] args = (String[])appContext.getArguments().get(IApplicationContext.APPLICATION_ARGS);
 ...
}

My product appName property matches my launcher name. And
--launcher.defaultAction
openFile
is present in my <launcher>.ini

Everything works fine in 2 cases:
1. I launch my application with the command line argument only once. Here "proccessCmdLineArguments" method works.
2. For the first time I launch my application without command line arguments. And then I can launch it with a command line argument as many times as I wish. Here "handleEvent" method works.

The problem is the third case, when I launch my application with the command line argument for the first time and do it again for the second time. After the default timeout (60 sec) Eclipse tries to create a new instance of my application instead of opening the file in the running instance. What am I doing wrong?
Re: Open file from command line (Pure E4 RCP) [message #1021480 is a reply to message #1021151] Wed, 20 March 2013 07:40 Go to previous messageGo to next message
Severin Raevskiy is currently offline Severin RaevskiyFriend
Messages: 5
Registered: March 2013
Junior Member
Sorry, I meant this article: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fproduct_open_file.htm&cp=2_0_21_8
Re: Open file from command line (Pure E4 RCP) [message #1022120 is a reply to message #1021480] Thu, 21 March 2013 09:59 Go to previous messageGo to next message
Severin Raevskiy is currently offline Severin RaevskiyFriend
Messages: 5
Registered: March 2013
Junior Member
It works, when I put an argument in <launcher>.ini. It also works when I connect with a remote debugger and start step-by-step debugging of "getNonFramework" method calls in EclipseEnvironmentInfo class. Looks like a race between threads. Any ideas?
Re: Open file from command line (Pure E4 RCP) [message #1022589 is a reply to message #1021151] Fri, 22 March 2013 07:29 Go to previous messageGo to next message
Severin Raevskiy is currently offline Severin RaevskiyFriend
Messages: 5
Registered: March 2013
Junior Member
Maybe a minimal application can help? I moved listener attachment from addon to "getApplicationDisplay()" method in my own application class.
Re: Open file from command line (Pure E4 RCP) [message #1498292 is a reply to message #1021151] Thu, 04 December 2014 09:56 Go to previous messageGo to next message
Robert Nica is currently offline Robert NicaFriend
Messages: 1
Registered: December 2014
Junior Member
Hi, Could you finally solve this problem?
I'm facing the same issue right now in Windows. If i launch the application with the --launcher.openFile myFile.txt parameter for the first time, it looks like the SWT event is not captured, or at least my listener is not notified. The second time it captures the event and works well, so i can only open files if the application is already running.
The -name parameter behaviour is also strange, as you explained. It happens to me too.
In Mac OS all works fine. I'm using Eclipse 4.4 Luna.
Any help would be great...
Re: Open file from command line (Pure E4 RCP) [message #1779307 is a reply to message #1498292] Fri, 05 January 2018 08:13 Go to previous messageGo to next message
Ralf Treu is currently offline Ralf TreuFriend
Messages: 1
Registered: January 2018
Junior Member
I had the same problem (works like a charm when I first start the application without file parameter, but works only the first time when I run it with file parameter) and noticed it was caused by my <launcher>.ini file having the -vm option set. It worked when I removed that line from the ini file. Since I need my application to run with a specific version I tried setting dll or exe specifically, rather than just pointing to the jvm bin folder. With the dll the problem persists, but setting the path to the javaw.exe solved it for me.

See Andrew Niefers comment on this topic in his blog (unfortunately cannot link to it directly because I just registered here.. tssk).

Re: Open file from command line (Pure E4 RCP) [message #1821906 is a reply to message #1779307] Sat, 22 February 2020 15:43 Go to previous message
Gerhard Kreuzer is currently offline Gerhard KreuzerFriend
Messages: 6
Registered: May 2019
Junior Member
Hi there,
I'm facing the same problem (pure E4 RCP on Windows), but setting the VM to a specific version of javaw.exe (which would solve the problem) is not an option for me.
I experimented with the Eclipse IDE and there all works as expected. But in my pure E4 RCP it works only, if the first instance is started w/o any files on the command line. In essence the IDE itself is also an E4 application, therefore I expect, that there exists an solution and I (we) just miss something...
Does anyone have a clue / any hint what is going wrong here?
Thanks in advance!

Addendum: I think I figured out the reason: https://bugs.eclipse.org/bugs/show_bug.cgi?id=560428

As a workaround until the bug is fixed in the native launcher, you can use your own E4Application class. At the beginning of the start() method you should take the current time (long timeOnEntryInMillis = System.currentTimeMillis();) and just before calling workbench.createAndRunUI(workbench.getApplication());
insert this:
while (display.readAndDispatch() || ((System.currentTimeMillis() - timeOnEntryInMillis) < 1000))
{
// nothing in here
}

[Updated on: Sun, 23 February 2020 10:38]

Report message to a moderator

Previous Topic:Pitfalls when command executes another command?
Next Topic:Specify theme-specific preferences via CSS
Goto Forum:
  


Current Time: Fri Apr 19 06:42:08 GMT 2024

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

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

Back to the top