25

I understand how to run my application with command line arguments using the run configuration menu.

The problem I have is that no matter what I update these command line arguments to, eclipse does not reflect these updates when I execute the code.

so far I have set the arguments to:

test1.txt test2.txt dfs

and this will print:

args[0] = test1.txt
args[1] = test2.txt
args[2] = dfs

but if I update the arguments and re-run it, the arguments won't update

How can I "reset" the arguments and re-run the application using the updated arguments.

The above and below both function correctly and it was in fact eclipse that was causing me issues. The problem was resolved with a simple restart of eclipse.

Thanks all.

  • Go to Run Configurations, make your changes, press the 'Apply' button (or just press 'Run'). – Thomas W Oct 28 '13 at 23:11
  • @ThomasW tried that and it remains the same –  Oct 28 '13 at 23:13
  • @cedwards93 You need to edit the program arguments and not the Vm arguments – An SO User Oct 29 '13 at 02:29
  • I'm going with "it works!" as per Little Child's answer. Must be user error.. don't know what you're doing wrong, maybe you're not re-running it, running a different configuration from the one you're editing or something weird? If all else fails, restart Eclipse. – Thomas W Oct 29 '13 at 03:43

4 Answers4

52
  1. Click on Run -> Run Configurations
  2. Click on Arguments tab
  3. In Program Arguments section , Enter your arguments.
  4. Click Apply

It is sure to work cause I tried it in mine right before I wrote this answer

An SO User
  • 24,612
  • 35
  • 133
  • 221
3

There is a situation (bug) where modifying the Run -> Run Configurations arguments does not work, since the actual run configuration being executed is actually hidden from you.

So updating the visible one will not be reflected in your actual run.

Example:

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class EclipseRunConfigurationTest {

    @Test
    public void test() {
        assertEquals("foo", System.getProperty("runProperty"));
    }

}
  1. Run it - it will fail.
  2. Modify the run configuration using the method specified by Little Child. add "-DrunProperty=foo" VM parameter
  3. Run it again - it will pass
  4. Debug it, then switch to the debug view,
    • RClick the Junit launch -> Edit Rerun EclipseRunConfigurationTest...
    • Change the VM parameter to "-DrunProperty=bar"
    • Apply and Debug - it will fail
  5. Open the Run/Debug manager again
    • Note that 'Rerun EclipseRunConfigurationTest' is not listed.
    • Note that the VM parameter is still "-DrunProperty=foo"
    • No amount of changing it makes the slightest bit of difference.

I shall file a bug report.

The above was run on Eclipse Kepler running on Fedora 20.

Tim
  • 726
  • 5
  • 18
2

A small update in the solution given by Little Child above, to make it work with arguments having spaces in them. e.g. first argument - abc def second argument - ghi third argument - jkl mno pqrs

In Program Arguments, give them like this using double quotes

"abc def"
"ghi"
"jkl mno pqrs"

If you don't give spaces it will take abc as first argument and def as second argument and ghi as thrid argument and so on..

Madhu
  • 71
  • 1
  • 5
1

For Eclipse Neon Users

Step 1: Click Run -> Run Configurations

Step 2: Click on arguments Tab.

Step 3: insert required arguments in VM Arguments.

Step 4: Click Apply

Step 5: Click Run.