101

I am developing on Eclipse on Windows and Code gets deployed on Unix. I am fetching the system property values using System.getProperty("key") ... How do I pass this in Eclipse so that I do not have to modify the code and it works on Eclipse for debugging?

Any suggestions?

abarisone
  • 3,707
  • 11
  • 35
  • 54
Devang Kamdar
  • 5,617
  • 8
  • 24
  • 16

5 Answers5

142

Run -> Run configurations, select project, second tab: “Arguments”. Top box is for your program, bottom box is for VM arguments, e.g. -Dkey=value.

Bombe
  • 81,643
  • 20
  • 123
  • 127
53

You can use java System.properties, for using them from eclipse you could:

  1. Add -Dlabel="label_value" in the VM arguments of the test Run Configuration like this:

eclipse_vm_config

  1. Then run the test:

    import org.junit.Test;
    import static org.junit.Assert.assertEquals;
    
    public class Main {
        @Test
        public void test(){
            System.out.println(System.getProperty("label"));
            assertEquals("label_value", System.getProperty("label"));
        }
    }
    
  2. Finally it should pass the test and output this in the console:

    label_value
    
madx
  • 6,723
  • 4
  • 55
  • 59
13

You can add command line arguments to your run configuration. Just edit the run configuration and add -Dmyprop=value (or whatever) to the VM Arguments Box.

izb
  • 50,101
  • 39
  • 117
  • 168
  • 4
    If you meant "Program Arguments box" when you said "command-line args box" under Arguments tab - Does not Work! Has to be entered in "VM Arguments Box" as mentioned by Bombe above. – Devang Kamdar May 14 '09 at 09:42
4

This will work for junit. for TestNG use following command

-ea -Dmykey="value" -Dmykey2="value2"
0

Yes this is the way:

Right click on your program, select run -> run configuration then on vm argument

-Denv=EnvironmentName -Dcucumber.options="--tags @ifThereisAnyTag"

Then you can apply and close.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459