How do I get the command-line for an Eclipse run configuration? - eclipse

I have several JUnit run configurations in Eclipse that I need to replicate on the command-line in order to use a third-party analysis tool. So far I've just been writing the command-line manually by looking at the run configuration and writing the appropriate classpath and command-line arguments.
Eclipse's run configurations (normal, JUnit, or other) must ultimately boil down to a command-line anyway, so how and where do I find that?

I found a solution on Stack Overflow for Java program run configurations which also works for JUnit run configurations.
You can get the full command executed by your configuration on the
Debug tab, or more specifically the Debug view.
Run your application
Go to your Debug perspective
There should be an
entry in there (in the Debug View) for the app you've just executed
Right-click the node which references java.exe or javaw.exe and
select Properties In the dialog that pops up you'll see the Command
Line which includes all jars, parameters, etc

You'll find the junit launch commands in .metadata/.plugins/org.eclipse.debug.core/.launches, assuming your Eclipse works like mine does. The files are named {TestClass}.launch.
You will probably also need the .classpath file in the project directory that contains the test class.
Like the run configurations, they're XML files (even if they don't have an xml extension).

To elaborate on rob's answer.
Make sure you open the debug view. Steps to open it: Window -> Show View -> Other -> (Search debug) -> Open
Then do what he references:
Run your application
Go to your Debug perspective
There should be an entry in there (in the Debug View) for the app you've just executed
Right-click the node which references java.exe or javaw.exe and select Properties In the dialog that pops up you'll see the Command Line which includes all jars, parameters, etc

Scan your workspace .metadata directory for files called *.launch. I forget which plugin directory exactly holds these records, but it might even be the most basic org.eclipse.plugins.core one.

Related

Is it possible to set which file to run by default in eclipse?

I'm writing a python project in Eclipse with the PyDev plug-in, which contains multiple files.
However I'm used to using visual studio, where it'll automatically find the main function of a project and run the program from there.
Eclipse will always run the file I am currently editing (which usually is a file containing function that are called from the main function).
Is it possible to set which file should be run then clicking run? I've looked at the launch options under Project->Properties->PyDev, but didn't find what I was looking for.
When you press the Debug or Run button (Debug on the left) Eclipse tries to intelligently determine what to launch based on your current editor.
You can change the behaviour by editing Window -> Preferences -> Run/Debug -> Launching -> Launch Operation as pictured below.
The default of launching the current editor works well for some languages, but not as well for Python when every single file is itself a valid program to run. In your case I recommend changing to Always launch the previously launched application.
You can create a custom run configuration.
Right click on your project > run as > run configurations
From here is just a matter of choosing your project type on the left hand side and filling in the required information. You can click 'Run' to use your new configuration.
To get to this configuration again, you can click the 'Run' drop down button in the eclipse tool bar and see all of your run configurations.
Hope this helps!

How can I clean up Eclipse "run configurations"

I set my java runtime options in Eclipse's Window > Prefs > Java > Installed JREs > Default VM Arguments. Since this setting is sufficient for all my main() entry points, I do not bother with customizing the "run configurations". It looks like nice flexibility but I probably will never need it. I was worried that I would have to repeat my VM arguments in the run configurations and so I started to copy my VM arguments but after an experiment it seems that I do not have to. Now I will have the opposite worry that I have some unintended customizations.
To eliminate the second worry, is there a way to eliminate the clutter visible in the Run drop down menu? What about the "Launch configurations" visible in the JAR export dialog? Is a run configuration the same thing as a launch configuration? How do I eliminate the multiple launch configurations?
I am on Eclipse Indigo on Ubuntu.
Edit After I manually delete all the run configurations, and proceed to do an export, buttons are greyed-out so I can't proceed. When I select the launch configuration drop-down, I end up with only one choice, from an unrelated project. I then created a run configuration for the real main entry point for the current project. I expect the clutter will return as I continue to use Eclipse.
One simple way would be to organize your projects by Eclipse workspace, which would limit the "run configurations" list only to the project referenced in a given workspace.
Switching workspaces would reset that list to the ones recorded for the projects of the new workspace.
Note: the OP's answer regarding launches file location isn't the only location possible.
The official one is:
${WORKSPACE}/.metadata/.plugins/org.eclipse.debug.core/.launches
But you can copy them enywhere else you want (as explained in "How do I save Eclipse launch profiles across workspaces?"), either by manually copying those files or by sharing them:
See "Which eclipse files belong under Version Control".
Once you know where they are saved, a simple delete is enough to make them disappear from the launcher menu.
The answer comes from #Francisco Puga
Experimental evidence shows that deleting "launches" seems to make run configurations disappear so it would seem that they might be synonymous.

Make Eclipse "run configuration" show up in context menu of specified file type

I have a simple Eclipse run configuration launching a Perl script to process an XML file. Nothing special, works alright.
However, picking the run configuration is a bit awkward. My entry doesn't show up in the first level of the context menu. It doesn't show up either under "Run As". I have to pick "Run As > Run Configurations ..." to then select my run configuration "import XML".
The way I'd like this to work is to select one or more XML files and then pick "import XML" (the name of my run configuration) from the context menu. Heck, the best thing would even to be able to double-click the XML file to launch it such as in Windows Explorer. Actually, it would be best if Eclipse were able to determine the applicability of my run configuration "import XML" based on the filename and folder location. Like, make the rc available for all files in Database/XML ending in .xml and not starting with Hooks.
Is there a way to get somewhere near that point? If some Java programming is involved that's not a problem.
The thing you're after is called launch shortcut, check out Eclipse help.
If you want to get something into the first level of context menu, use org.eclipse.ui.menus extension point. Double-click is associated with opening a file in editor. While it is possible to define your launch configuration as an editor, it's certainly not a good practice.
My entry doesn't show up in the first level of the context menu. It doesn't show up either under "Run As". I have to pick "Run As > Run Configurations ..." to then select my run configuration "import XML".
I don't think any run configurations are supposed to show up in the context menu under Run As, although it seems like it should probably contain recently used configurations, to mirror the toolbar run/debug/etc. buttons. Speaking of which, does your launch configuration show up under the run button? It should. That might be the easiest way to go about this.
The way I'd like this to work is to select one or more XML files and then pick "import XML" (the name of my run configuration) from the context menu. Actually, it would be best if Eclipse were able to determine the applicability of my run configuration "import XML" based on the filename and folder location. Like, make the rc available for all files in Database/XML ending in .xml and not starting with Hooks.
Eclipse can't do anything like this out of the box. It's entirely possible to write your own plug-in to do this, though I imagine the effort required would be enough to make it not worth it for what sounds like a one-off program. If I were you I'd probably just keep a console window open and run it from there, or make a really really simple gui to do this.
Some googling has shown that what I'm looking for, i.e. a context menu plug-in, has already been done; it is aptly named the ContextMenuPlugin for Eclipse.

Launch and debug a single script in PyDev

I am a beginner in using Eclipse and PyDev (Aptana Studio 3). I am not used to and i don't understand the workflow in such big IDEs as Eclipse.
I have a simple task: i have a simple Python script, which i want to open and run in Eclipse, having its output in Eclipse console. Or debug it.
Until now i used another IDE called Eric4, which allowed me to do what i want - open a file and run immediately, without creating a project or setting up launch configurations.
Is this possible in Eclipse, or i have to create a project for each file i want to run or debug? I want to understand how it works.
I guess i understand that creating a project is needed at least for settings up the paths (PYTHONPATH), but if it's a single script - somehow to use by default the current directory?
For example i have a folder called snippets where i keep a lot of python scripts which demonstrate some functionality. How do i open these files one by one and run them?
Most of my coworkers launch python scripts in a separate console - python my_scipt.py.
You need to have at least one project with the configuration you want (i.e.: syntax type, interpreter), then, open the file you want to run and press F9.
If it's an external file -- i.e.: a file that's not under a project in Eclipse -- it'll ask you to associate a project with the launch to get the needed information for the launch, but the file doesn't really have to be in the project (note that you can drag external files from your filesystem into Eclipse to open them).
I suggest you follow the steps on the getting started: http://pydev.org/manual_101_root.html (it guides you to configuring PyDev and explains how to do a run/debug session).

How to execute or implement batch file in java project with eclipse

Is it possible to implement or extract batch file in eclipse and debug java project in debug mode. Because without batch file I can't debugging my project and can't set breakpoint.Or some another solution. How to debug my application with use .bat file to start my java project.
Is it possible to implement or extract batch file in eclipse and debug java project in debug mode.
Hmm... You can do everything you do with a batch file (assuming you're using it to start a Java program of course) from Eclipse with a Run > Run Configuration... (also available from the contextual menu after a right-click or via the top toolbar).
Because without batch file I can't debugging my project and can't set breakpoint.
Why?! I don't think this is true.
Or some another solution.
Start your class/project in debug mode using Run > Debug (reusing or creating a new Run > Debug Configuration...). Again, this is also available from the contextual menu after a right-click or via the top toolbar.
How to debug my application with use .bat file to start my java project.
To be fully exhaustive, you can run an external program from Eclipse using an Run > External Tools > External Tools Configuration.... And you could indeed use remote debugging options and connect a remote debugger from Eclipse. But honestly, I don't think you need that.
Maybe you should explain what you're trying to do more precisely.
Try remote debugging. Eclipse can attach to remote Java processes, but the Java program must be started with special keys. I don't remember them, google/help for your service.