Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » How can I pass arguments to the main method?
How can I pass arguments to the main method? [message #634752] Sat, 23 October 2010 04:04 Go to next message
Nishika N Jones is currently offline Nishika N Jones
Messages: 1
Registered: October 2010
Junior Member
1. Choose Options from the Configure menu.
2. Select JDK Tools, select Run Application from the pulldown list, Edit.
3. The Tool Configurations dialog box will be displayed.
4. Enable the checkbox ''Prompt for main method arguments"

Is there anyother way apart from this.


Re: How can I pass arguments to the main method? [message #634856 is a reply to message #634752] Sun, 24 October 2010 17:02 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 1024
Registered: July 2009
Senior Member
Nishika N Jones wrote on Sat, 23 October 2010 06:04
1. Choose Options from the Configure menu.
2. Select JDK Tools, select Run Application from the pulldown list, Edit.
3. The Tool Configurations dialog box will be displayed.
4. Enable the checkbox ''Prompt for main method arguments"

Is there anyother way apart from this.


I don't see any of these menus/options.
Which tool exactly are you using?

Stephan

Re: How can I pass arguments to the main method? [message #656499 is a reply to message #634856] Fri, 25 February 2011 22:45 Go to previous messageGo to next message
Phil Freihofner is currently offline Phil Freihofner
Messages: 32
Registered: May 2010
Member
Hi - I was similarly trying to figure out how to pass arguments to a "main" that expects input, and came across the above cryptic exchange. (Seems like some posts are missing? I see just two posts.)

Here is what I ended up doing, using Helios.
Select Run --> Run Configurations...
Select tab: "(x)= Arguments"
Entered my arguments in the text box labeled "Program arguments:"
Click Run.

The arguments entered persist with the click of the Run shortcut.

Perhaps there is a way to have the IDE prompt for arguments, which would beat having to click through to the "Program arguments:" text box each time. Still, having this option is better than nothing!
Re: How can I pass arguments to the main method? [message #656503 is a reply to message #656499] Fri, 25 February 2011 23:14 Go to previous messageGo to next message
Phil Freihofner is currently offline Phil Freihofner
Messages: 32
Registered: May 2010
Member
I just figured out another option for passing arguments to main: use the Scrapbook! The following syntax works for a single argument. Note that the arguments have to be within a string array.

String[] input = {"MyInput1"};
MyClass.main( input );


Highlight the entire in the scrapbook, right click and select "Execute".

Instructions for making a Scrapbook can be found via a Help Search on "scrapbook". If there is an even easier way, I'd love to know about it! Thanks.
Re: How can I pass arguments to the main method? [message #656517 is a reply to message #656499] Sat, 26 February 2011 05:49 Go to previous messageGo to next message
David Wegener is currently offline David Wegener
Messages: 1346
Registered: July 2009
Senior Member
On Fri, 2011-02-25 at 17:45 -0500, Phil Freihofner wrote:
> Hi - I was similarly trying to figure out how to pass arguments to a "main" that expects input, and came across the above cryptic exchange. (Seems like some posts are missing? I see just two posts.)
>
> Here is what I ended up doing, using Helios.
> Select Run --> Run Configurations...
> Select tab: "(x)= Arguments"
> Entered my arguments in the text box labeled "Program arguments:"
> Click Run.
>
> The arguments entered persist with the click of the Run shortcut.
>
> Perhaps there is a way to have the IDE prompt for arguments, which would beat having to click through to the "Program arguments:" text box each time.. Still, having this option is better than nothing!
You can use the Eclipse Variables feature in the Run Configurations
dialog. While on the Arguments Tab, click on the Variables Button. In
the popup dialog is a list of variables that Eclipse will substitute
when running the launch config. One of the variables is String Prompt.
This allows you to enter a prompt string with a text field where the
user can enter any text. The prompt will be shown at each launch. You
can even enter default data.

The variable ${string_prompt:Enter program args:One} will cause Eclipse
to display a popup with the prompt Enter Program args on one line and a
text field filled in with One.
Re: How can I pass arguments to the main method? [message #657428 is a reply to message #656517] Wed, 02 March 2011 18:34 Go to previous message
Phil Freihofner is currently offline Phil Freihofner
Messages: 32
Registered: May 2010
Member
Yay! Thank you.
Previous Topic:JRE_CONTAINER empty when creating a new JavaProject
Next Topic:run from command line
Goto Forum:
  


Current Time: Thu Oct 30 15:31:14 GMT 2014

Powered by FUDForum. Page generated in 0.01802 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software