Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How to add a custom launcher to a perspective(Adding a launcher to a perspective)
How to add a custom launcher to a perspective [message #1814307] Mon, 09 September 2019 08:56 Go to next message
Mihnea-Costache Marin is currently offline Mihnea-Costache MarinFriend
Messages: 68
Registered: September 2019
Member
Hello,

I am trying to create a custom launcher to run my plugin and I want to add it to my custom perspective. Is there a way to do that? I've tried a couple of times after looking it up online on how to do it but with no success.

Thank you!
Re: How to add a custom launcher to a perspective [message #1814387 is a reply to message #1814307] Tue, 10 September 2019 18:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 32390
Registered: July 2009
Senior Member
I have a feeling there isn't really a good way to do that. "Local" launchers are stored in the workspace's .metadata, i.e., <workspace>/.metadata/.plugins/org.eclipse.debug.core/.launches/*.launch, so there isn't really a way to contribute that...

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to add a custom launcher to a perspective [message #1814412 is a reply to message #1814387] Wed, 11 September 2019 07:14 Go to previous messageGo to next message
Mihnea-Costache Marin is currently offline Mihnea-Costache MarinFriend
Messages: 68
Registered: September 2019
Member
To be more explicit, my plugin creates some custom files written in C. After building the project(make all), I get a file. Let's call it file.extension. Is there a way to pass this file to another application(a simulator for example) with some custom arguments PROGRAMATICALLY?

Thanks!
Re: How to add a custom launcher to a perspective [message #1814424 is a reply to message #1814412] Wed, 11 September 2019 09:20 Go to previous messageGo to next message
Emmanuel Chebbi is currently offline Emmanuel ChebbiFriend
Messages: 123
Registered: February 2018
Senior Member
Hi,

If by "pass this file to another application with some custom arguments programmatically" you mean "run a Launch Configuration with custom arguments programmatically" then yes, there are ways to do that.

Basically, once you have created your Launch Configuration type with some arguments [1] then you can create a new Launch Configuration programmatically, set its arguments then launch it. See [2] for an example.

Your code would be something like the following (not tested):
// Create a new Launch Configuration
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
ILaunchConfigurationType type = manager.getLaunchConfigurationType(YOUR_LAUNCH_CONFIGURATION_TYPE_ID);
ILaunchConfigurationWorkingCopy configuration = type.newInstance(null, "Name of the new Launch Configuration");

// Set its attributes (here, we give it the path to the file.extensions you generated)
configuration.setAttribute("generated file", pathToGeneratedFile);

// Launch the configuration
configuration.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor();

In case you want to launch an existing Java application based on JDT's Launch Configuration then I believe that [2] could be a good starting point.

[1] https://www.vogella.com/tutorials/EclipseLauncherFramework/article.html#creating-a-new-launch-configuration-type
[2] https://www.eclipse.org/articles/Article-Java-launch/launching-java.html
Re: How to add a custom launcher to a perspective [message #1814433 is a reply to message #1814424] Wed, 11 September 2019 11:55 Go to previous messageGo to next message
Mihnea-Costache Marin is currently offline Mihnea-Costache MarinFriend
Messages: 68
Registered: September 2019
Member
What I mean by "pass this file to another application with some custom arguments programmatically" is the following (just an example, not the actual thing).

1. Run the plugin
2. Workbench opens. I create my type of project
3. Creating the project also created some files inside it.
4. Build the project => I get an executable
5. This executable SHOULD be then passed to an application(to put it more explicit, let's say after building the project I get an image(the executable) and I want to pass that image to, let's say, Photoshop(which is the simulator)) with some arguments.

Hope I was clear enough!
Re: How to add a custom launcher to a perspective [message #1814436 is a reply to message #1814424] Wed, 11 September 2019 12:53 Go to previous messageGo to next message
Mihnea-Costache Marin is currently offline Mihnea-Costache MarinFriend
Messages: 68
Registered: September 2019
Member
To be even clearer, after building the project, I get a binary. How can I run that binary with another program by also providing some arguments?
Re: How to add a custom launcher to a perspective [message #1814437 is a reply to message #1814433] Wed, 11 September 2019 12:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 32390
Registered: July 2009
Senior Member
You can use variables in the launch configuration so you can use Variables... to choose resource_loc and use Configure... to locate the executable in the workspace. Note also that the last tab of the launch configuration lets you specify "Shared File" so you can locate the *.launch in one of your projects in the workspace so that it's always available in every workspace where you've imported your project.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to add a custom launcher to a perspective [message #1814439 is a reply to message #1814424] Wed, 11 September 2019 13:20 Go to previous messageGo to next message
Mihnea-Costache Marin is currently offline Mihnea-Costache MarinFriend
Messages: 68
Registered: September 2019
Member
Sorry for so many messages, I'm just trying to explain the situation as best as possible to maybe give you a bit of help in order to help me.

Basically, what I have to do is create an external tools configuration where I will use Program and need to programmatically specify the location of the program that is going to use the binary, the working directory(which is the project located in the workspace) and the arguments.
Re: How to add a custom launcher to a perspective [message #1814440 is a reply to message #1814439] Wed, 11 September 2019 13:23 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 32390
Registered: July 2009
Senior Member
Emmanuel explained how to create a launcher programmatically. Everything you can do in the IDE manually you can do programmatically via the APIs he described and can even launch it programmatically.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to add a custom launcher to a perspective [message #1814442 is a reply to message #1814440] Wed, 11 September 2019 13:44 Go to previous messageGo to next message
Mihnea-Costache Marin is currently offline Mihnea-Costache MarinFriend
Messages: 68
Registered: September 2019
Member
You are very correct. I finally managed, after one week, to create that configuration. But, and I'm hoping you might have an idea, I'm not exactly sure about one thing. I have the method which creates the configuration with all the attributes and value. The problem is, I don't know where to use. Meaning, I have a class which creates my type of project, but I can't put it there because it runs at the same time the project is created and then disappears.

Do you have any ideas?
Re: How to add a custom launcher to a perspective [message #1814453 is a reply to message #1814442] Wed, 11 September 2019 15:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 32390
Registered: July 2009
Senior Member
Your descriptions are a little vague, but you can save a launch configuration via org.eclipse.debug.core.ILaunchConfigurationWorkingCopy.doSave(int) and can save it in the workspace by calling org.eclipse.debug.core.ILaunchConfigurationWorkingCopy.setContainer(IContainer) first (with IContainer being the IProject or IFolder in which you want it to be saved).

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to add a custom launcher to a perspective [message #1814454 is a reply to message #1814442] Wed, 11 September 2019 15:37 Go to previous message
Emmanuel Chebbi is currently offline Emmanuel ChebbiFriend
Messages: 123
Registered: February 2018
Senior Member
To be honest, I'm not sure that I trully understand what you are trying to achieve. If I sum up what I understood, your use case is the following:

  • Write some C code
  • Generate a file/executable by building the project
  • Run another binary programmatically, giving it the generated file/executable as an argument

And if have understood your last message correctly, so far you managed to:

  • Generate a file/executable by building your project
  • Programmatically create an External Tool configuration that executes the 'other binary'

and you are currently trying to determine how to run the code that either launches the External Tool or create a Launch Configuration that your users can run as they wish.

Am I right so far?

If that's the case, then you can for instance:

  • add a button in Eclipse IDE's UI that would launch the other binary on press [1]
  • add a dedicated context menu that would allow to launch the other binary by a right-click on your project [1, 2, 3]
  • add a custom Project Builder to your project so that your code is automatically executed after the compilation of your C code [4]

[1] https://www.vogella.com/tutorials/EclipseCommands/article.html
[2] https://www.vogella.com/tutorials/EclipseProjectNatures/article.html
[3] https://www.programcreek.com/2013/02/eclipse-rcp-tutorial-add-a-menu-item-to-the-popup-menu-when-right-click-a-file/
[4] https://www.vogella.com/tutorials/EclipseBuilder/article.html

[Updated on: Wed, 11 September 2019 15:50]

Report message to a moderator

Previous Topic:Save/restore project settings from team(git) repository
Next Topic:Debugging - Slow jump to source location
Goto Forum:
  


Current Time: Mon Jun 27 12:52:22 GMT 2022

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

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

Back to the top