Results 1 to 3 of 3
  1. #1
    sriram56 is offline Member
    Join Date
    Nov 2011
    Rep Power

    Default Running Main from Command Line

    I have always run Main from an IDEA. How do I run Main from command line

  2. #2
    Join Date
    Nov 2011
    Northern Virginia, USA
    Rep Power

    Post Re: Running Main from Command Line

    At the root of your package subtree, use the java command and explicitly name the path to your directory and the class containing your static Main method. So, if your Main method is defined in class "MyClass," and MyClass is in package "MyProgram," cd to the parent directory of the MyProgram directory and enter this:

    >java MyProgram.MyClass

    If you are using the default package (that is, if there is no "package" statement in the file defining the class that includes your Main method), just cd to the directory containing MyClass and enter this:

    >java MyClass

    If your package is more complex, like com.novadatalabs.myprogram, you need to cd to the parent of com/novadatalabs/myprogram and enter this:

    >java com.novadatalabs.myprogram.MyClass

    This sure confused me the first few times I tried it outside the NetBeans IDE that I use. Even if you are in the right directory when you run the java command and you enter the right package path and Main class file name, don't be surprised if you still have problems. Your IDE may be supplying a lot of runtime options for you. Start with the simplest possible "Hello World!" sort of program and get that running from the command line first. Then work your way up from there to more complex situations.

    Best of luck!
    Last edited by stevensrmiller; 11-26-2011 at 05:03 AM.

  3. #3
    javin.paul is offline Banned
    Join Date
    Oct 2011
    Rep Power

    Default Re: Running Main from Command Line

    You just need to be aware of Classpath and Path , once these are set properly you can run it. check out on how to run Java program from command line, you may find useful.

Similar Threads

  1. Replies: 0
    Last Post: 04-20-2011, 01:03 PM
  2. Error While Running Windows Command Line Instruction
    By divs1210 in forum AWT / Swing
    Replies: 5
    Last Post: 04-13-2011, 05:09 PM
  3. Running Jar file using command line through Java Codes
    By NaturalE in forum Advanced Java
    Replies: 2
    Last Post: 02-24-2011, 05:07 AM
  4. Replies: 3
    Last Post: 08-25-2010, 11:21 AM
  5. Replies: 1
    Last Post: 06-30-2009, 03:32 PM

Posting Permissions

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