Invoking Java main method with parameters from Eclipse

后端 未结 6 834
终归单人心
终归单人心 2020-11-28 05:59

During development (and for debugging) it is very useful to run a Java class\' public static void main(String[] argv) method directly from inside Eclipse (using th

6条回答
  •  被撕碎了的回忆
    2020-11-28 06:31

    Uri is wrong, there is a way to add parameters to main method in Eclipse directly, however the parameters won't be very flexible (some dynamic parameters are allowed). Here's what you need to do:

    1. Run your class once as is.
    2. Go to Run -> Run configurations...
    3. From the lefthand list, select your class from the list under Java Application or by typing its name to filter box.
    4. Select Arguments tab and write your arguments to Program arguments box. Just in case it isn't clear, they're whitespace-separated so "a b c" (without quotes) would mean you'd pass arguments a, b and c to your program.
    5. Run your class again just like in step 1.

    I do however recommend using JUnit/wrapper class just like Uri did say since that way you get a lot better control over the actual parameters than by doing this.

提交回复
热议问题