Eclipse: what's the good way of launching an application with arguments? - eclipse

I've been using Eclipse for years, and I'm quite familiar with it, but this still bothers me, I want to know if I'm missing something.
Suppose I want to run my runnable MyClass.java from the IDE. The standard way is, with the source selected
Right Click -> Run-As -> Java Application
or, equivalently through the Menu -> Run -> Run-As -> Java Application
Now, suppose I want to run it with some arguments, or some special setting (output redirection, alternate JRE, etc). In Eclipse, that's managed via Launch Configurations. In my case, I'd do Right Click -> Run-As -> Run Configurations... to access the stored Configurations, find the one (perhaps several) corresponding to MyClass, edit the settings and run it.
Now, here's my little problem. If I wanted to run MyClass with arguments straight away... it seems that I need to go through this two-step procedure: 1) run it for a first time without arguments so that Eclipse (under the hood, rather misteriously) creates a blank Launch Config, and 2) invoke Run As... so that the LaunchConfig editor is opened? It looks cumbersome and unnatural to me.
I'd wish to do "Run as Java, let me edit the configuration first".
Of course, I can go Right Click -> Run-As -> Run Configurations... and create manually the configuration, but this is not ideal : Eclipse does not autofill the Java source from which I triggered the creation, nor even can guess the application type (Java in this case), I must do this myself (that's why I resign to the 2-step procedure mentioned above, it's more direct).
Notice that this is not specific to running Java apps.
Am I missing something?

You may add variables to the Run config and prompt the user to enter the value when you run the application.
I have attached an example -
Next time when you run the application it will directly prompt you to enter the value.
Hope that helps !

Related

Is there a macro facility for NetBeans commands?

I have a very common workflow in NetBeans:
Shutdown a Tomcat server
Do a clean and build
Launch a J2EE application (and Tomcat) in DEBUG mode.
Theree are a number of variants to this I use, but basically I'd like to be able to click on one button and have all this done in sequence -- which also requires that the previous operation complete before the next operation is initiated.
The "record macro" facility doesn't seem to do this -- it seems to be specific to editor commands.
In the Run Menu, there is Repeat option (Ctrl-F11), I guess that is close to what you want.

Convenient way to run eclipse plugin

I have recently started developing an Eclipse plugin (which is basic stuff for now) and I am struggling with "default" way to run Eclipse plugin ("Run as Eclipse application").
The Eclipse is starting another instance with my plugin already installed in it (this is default behaviour).
The problem is that when I want to re-run my plugin project and I press "run" button again (or Ctrl + F11) (and the another Eclipse instance still running) I get following message:
"Could not launch the application because the associated workspace is currently in use by another Eclipse application".
The error makes sense, and when I close "testing" Eclipse instance I am able to run my plugin again.
The question is - "is it normal routine for plugin development?". Maybe I am missing something, e.g. special arguments for Eclipse?
This seems all pretty normal. The error message is since the run configuration is specifing a workspace and when you start a second instance using the same workspace it is locked and considered in use.
What I usually do when testing a plugin is to create a run configuration (click "Run...") where I disable all the plugins I wont need when testing. This makes sure that the test starts up a couple of seconds quicker. Make sure you save that run configuration as a *.launch file aswell, that makes it quicker to test the next time. Or it can be used to share the configuration.
There's a lot you can configure in the run configuration, such as eclipse arguments, vm argument, if you want environment variables set, etc. So be sure to experiment a little.
In your run configuration. Main tab->Workspace Data ->Location text box add this:
${workspace_loc}/../runtime-EclipseApplication${current_date:yyyyMMdd_HHmmss}
Note the suffix ${current_date:yyyyMMdd_HHmmss} by this every time you launch your application new workspace will be created. So you will not get any error message saying workspace is locked.
But be careful as the folder .metadata will be different for different instances as their work-spaces are different. Thus preferences stored/retrieved by different instances are NOT in sync.
You are probably missing one important point: Eclipse supports the Java hot code replacement. Therefore in many cases you can modify your Java code while your application Eclipse instance is running, save the code and continue without restarting.
If hot code replacement is not possible, Eclipse will tell you, so you always know whether the editing changes are applied to the running instance.
This works best with more recent versions of the JVM, so consider upgrading to the latest Java 7 version, even if you write code to be compliant with Java 1.5 or 6.

How to autorestart node.js application in Eclipse/Aptana Studio on source change while development?

This is not a question really, but a guide in some sense.
I did not find a better place to post it. I hope someone finds this helpful.
I was fed up with stopping and starting node.js application to pick up code changes.
So I wanted a solution without too much hassle and installation of additional plug-ins, packages or anything else. The pure solution using standard Aptana Studio 3.4 (Eclipse) features on Windows 8.1 x64 as follows:
Right-click on your project in Project Explorer > Properties > Builders
New... > Program > OK
Name: Terminate existing node.js process(es)
Location: C:\Windows\System32\taskkill.exe (${env_var:SystemRoot}\System32\taskkill.exe did not work for me, it might for you)
Working Directory: Browse Workspace... > select your project > OK
Arguments: /IM node.exe /F
Switch to Build Options tab and tick During auto builds, untick Launch in background > OK
Create another builder: New... > Program > OK
Name: Start <your-project-name>
Location: C:\Program Files\nodejs\node.exe (you can try ${env_var:ProgramFiles}\nodejs\node.exe as well)
Working directory: same as point #5
Arguments: app.js (or any other file for application entry point)
Switch to Build Options tab and tick both During auto builds and Launch in background > OK
Turn on project autobuild: Window > Preferences > General > Workspace, tick Build automatically > OK
Change default build order: Window > Preferences > General > Workspace > Build Order, untick Use default build order and remove all projects except your node.js project > OK
Restart Aptana/Eclipse (There are bugs, so sometimes preference changes are just not saved and get lost. You have to double-check.)
So if you have not changed too many default preferences in Aptana Studio 3/Eclipse by saving a file within your project should trigger its builders. First builder will kill existing instance to overcome 'port already in use' exception and start an application again. Console tab related to that process should pop up.
This works perfectly for me developing one node.js project at a time and medium size application restarts instantly. There is still space for improvements, e.g. killing just that particular instance instead of all. Suggestions are welcome (except the ones to install Nodeclipse or node.js packages, etc.)!
I hope this easy to do solution will help someone. Also I hope Aptana Studio 3 will start supporting node.js type of projects/server natively very soon.
You can use nodemon to restart node application whenever the code changes. Have a look https://github.com/remy/nodemon/
Welcome to Nodeclipse. Your solution is added to Nodeclipse Help Run page,
please edit. That is to answer "a better place to post it".
Alternatively, this question should have been broken into problem and solution part to fit stackoverflow.com Q&A format. Also constrains (like without plugin or Node.js modules) should be said in the topic as some percentage of stackoverflow.com users don't really read whole (especially long) question.
Then my answer is just use Debug View. (Actually it should be named Launch as it is both for Run and Debug) In your favorite perspective: Window -> Show View -> Others.. -> Debug. (In Nodeclipse Node perspective Debug View is visible by default)
Then you can right-click on launched application in Debug View and select Terminate and Relaunch. That is more explicit and allows to run many applications.
I also don't understand why you first say "without plugins" and don't suggest "to install Nodeclipse", but in the end add "I hope Aptana Studio 3 will start supporting". Wouldn't it be another plugin/extension? Nodeclipse as of 0.10 has code completion for base Node.js modules and improved support for black background color themes. Open an issue when ready to discuss/work together. Nodeclipse was started by developers like you who stopped hoping and waiting and just did it. One small piece at a time. Just like you did.
My two cents:
If you want to enable debugging too, you can do it by creating a Standalone V8 VM configuration and launching it with eclipse_remote_control. Steps:
Help > Install new software...
Work with: https://github.com/marook/eclipse-remote-control/raw/master/workspaces/erc/update_site
Select and install the plugin
Important: download eclipse_remote_control_client.jar form https://github.com/marook/eclipse-remote-control/raw/master/workspaces/erc/release/eclipse_remote_control_client_1.3.0.jar and place it where you later know (I placed in /Applications/eclipse/plugins/eclipse_remote_control_client_1.3.0.jar)
Restart eclipse
Once installed the new plugin, create a new debug configuration and project builder:
Run > Debug Configurations... > Right click Standalone V8 VM > New
Name: NodeV8-5858 (or whatever, remember it)
Port: 5858
Apply, Close
Project Explorer > Right click your project > Properties > Builders
New... > Program > Ok
Name: Start NodeV8
Location: /Library/Java/JavaVirtualMachines/jdk1.7.0_15.jdk/Contents/Home/bin/java (find your java location)
Working Directory: Browse Workspace... > select your project > OK
Arguments: -jar /Applications/eclipse/plugins/eclipse_remote_control_client_1.3.0.jar execute_command NodeV8-5858 DEBUG (replace with your .jar location and the name you selected in step 2)
Ok (then make sure that "Start NodeV8" remains the last entry in the list)
Select "Start " and click Edit...
Arguments: --debug-brk=5858 --harmony app.js (or any other file for application entry point)
Arguments: --debug=5858 --harmony app.js (if you don't want it to
wait at the beggining)
Ok and enjoy!
If you are working with mac, then to kill all node process you can create an script killallnode.sh with the following code:
#!/bin/bash
killall node
Place it somewhere you know and fill it in the location field for step 4.

Eclipse/PyDev/GAE: How do I add command line options to my Run As->PyDev Google App Run

I am using Eclipse/PyDev to develop a Google App Engine project called GAEServer. One of my common operations is to right click on the project and select Debug As->1 PyDev: Google App Run. Which kicks of a debug session for my application.
I would like to change the command line arguments executed when this command is invoked (to relocate where GAE local server looks for its database). This requires me to add arguments to the executed command.
If I select from the main menu: Run->Debug Configurations... there is an expandable item called PyDev Google App Run which contains a list of items:
PyDev Google App Run
GAEServer GAEServer
GAEServer GAEServer (1)
GAEServer GAEServer (2)
...
At the moment I have 19 of these which is a little surprising. If I select the first one then there is a tab where you appear to be able to add arguments (x)= Arguments but if I edit this and try to debug as again, it does not invoke GAE with the additional options, instead it creates another GAEServer GAEServer (n) with the default settings.
It may be that I have set up my project in some odd way, that I'm not understanding how this is supposed to work or that I have uncovered a bug. Can anyone help me figure out which?
Thanks in advance
Jules
The run as will really create a new run configuration... Just erase the bunch of configurations you have, run it once and edit that one.
Later ( if you followed the suggestion on http://pydev.org/manual_101_run.html ), you should be able to Ctrl+F11 to rerun the last launch done (or choose it from the menu: run > run history > previous launches: can be accessed through Alt+R, T, number of config).

How can I bind a specific key to different launch configurations in Eclipse?

I have several launch configurations for the code I work on.
One configuration (#1) means "run the unit tests for the file in the frontmost editor (i.e. selected resource)". I would really like to be able to always make this be bound to a key.
Another configuration (#2) means "run the server that I am working on (in the frontmost project) so I can test it interactively".
Yet another (#3) means "run some automated acceptance tests against the server".
I always want to have #1 close at hand, easy to run from a single keystroke. Plus, I want to be able to run #2, watch it start up in a console, and when it's ready (since it's not entirely trivial to automate this) hit the key for #3.
This is possibly similar to the question for binding a key to a specific build configuration, but the answers there look very specific to builds, and as I'm using PyDev, I don't have a "build" step at all.
Also, given that I'm using PyDev, an answer in the form of a pyedit_* script would be appreciated just as much as a "native" answer for eclipse.
Maybe Eclipse Runner plugin could make it easier for someone to handle launch configurations. It doesn't allow to assign key binding to launch configurations currently but I opened a feature request Key bindings for launch configurations
Not to a specific launch Configuration , but you can bind a key to run Last run Configuration ,
Windows->preferences->General->Keys->Run last launched external Tool
You can do the following (for #2 and #3), after having those run configurations created:
Go to Run > Run Configuration > Select the run configuration you want > Common > Display in Favorites Menu > Check Run/Debug. This will make it always appear as the first on the menu.
This will make it appear in the menu in Run > History and Run > Debug History, then, you can access it through Alt+R, T, 1 (and 2 and 3) to run your configurations or Alt+R, H, 1 (and 2 and 3) to debug.
And for #1, as Piotr Dobrogost said, you can just use Ctrl+F9 in the current editor and choose which test-cases you want to run (if you select a unit-test -- usually with Ctrl+Shift+Up or Ctrl+Shift+Down -- it'll be pre-selected for you) -- then, if you configured to always relaunch the last launch, as explained in http://www.pydev.org/manual_101_run.html, you can use Ctrl+F11 to relaunch the last launch.