Results 1 to 11 of 11
  1. #1
    Nakira is offline Member
    Join Date
    Oct 2008
    Location
    Aberystwyth
    Posts
    55
    Rep Power
    0

    Default Command Line Arguments

    Hi all. I'm a new user to NetBeans. (I started using it about 2 hours ago)
    I decided to give NetBeans a try as the latest version of Ubuntu came with it pre-installed. Now I've made many simple programs using it and I've even created a GUI application, however i came across a stumbling block when i couldn't figure out how to use command line arguments when running a compiled Java program. Is there a simple way to do this using NetBeans and if so could someone please kindly tell me how? :confused:

    Thanks in advance, Nak.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    Project --> right-click --> Properties --> run --> Arguments

    NetBeans does come with an extremely exhaustive help file, or didn't you know that?

    db

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes, that help page content all what you need. Explain all the concepts nicely.

    One thing you have to keep in mind. In NetBeans you cannot set arguments for a class, you have to do it for a project as db explain above. So be careful when you are dealing with command line arguments.

  4. #4
    chdieawoy is offline Member
    Join Date
    Dec 2008
    Posts
    1
    Rep Power
    0

    Post 新加的空白文章3

    这是新加的空白文章3,可以在ubb可视化编辑器中,添加和修改文章内容。

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Can you please ask your question in English. Other languages are not effective here. Please don't do this again.

  6. #6
    Sanford is offline Member
    Join Date
    Feb 2010
    Posts
    3
    Rep Power
    0

    Default Why are arguments at project level?

    Why would you configure arguments at the project level? That makes no sense. If I go to "Run->Set Project Configuration->Customize" and enter the class and the arguments, and then "Run->Run File", the arguments are not recognized. That is very confusing.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Sanford View Post
    Why would you configure arguments at the project level? That makes no sense. If I go to "Run->Set Project Configuration->Customize" and enter the class and the arguments, and then "Run->Run File", the arguments are not recognized. That is very confusing.
    I'm not clear what you mean. Setting up arguments on project level is required, based on the implementation.

  8. #8
    Sanford is offline Member
    Join Date
    Feb 2010
    Posts
    3
    Rep Power
    0

    Default Why are arguments at project level?

    I'm new to the Java/NetBeans world, but in my view a project consists of a group of classes (programs). Since arguments are specific to each program, why would you have to specify them at the project level? If I skip Net Beans and just run a java program from the command line, I can just enter:
    'java myprog.java arg1 arg2' and that works, correct? In NetBeans I can follow the rules and get it to work--the theory just makes no sense to me.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Netbeans needs to know what arguments you want passing to your app. Eclipse has a similar thing, though you can setup various run targets...I don't know if Netbeans allows you to do that. That means you can set up various different run configurations with different argument lists. Either way, though, these are defined at the project level.

    Where would you define them?

  10. #10
    Sanford is offline Member
    Join Date
    Feb 2010
    Posts
    3
    Rep Power
    0

    Default

    This is probably my lack of understanding of the Java/NetBeans environment. When writing an application in a language such as C, it is considered desirable for each program to be as independent from the others as possible (modularity). Argument values are sent either in a call from one routine to another, or indicated on the command line. You would not set up their values in something that is globally accessible, such an an include file.
    So in Net Beans I would think that an argument value would be restricted to the scope of one class, not defined for the scope of the entire project.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    But the command line argument represents the args sent into the app.
    The app that is your project.
    And most apps have only one entry point...one main().

Similar Threads

  1. command line args
    By MarkWilson in forum NetBeans
    Replies: 3
    Last Post: 08-04-2008, 04:22 AM
  2. Printing command line arguments
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-03-2007, 10:27 AM
  3. Replies: 1
    Last Post: 11-07-2007, 03:17 PM
  4. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 01:23 AM
  5. Java Command Line Arguments In Eclipse IDE
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 05-19-2007, 10:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •