Results 1 to 3 of 3
Thread: Running Main from Command Line
- 11-26-2011, 03:49 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 2
- Rep Power
- 0
- 11-26-2011, 04:44 AM #2
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.
- 11-26-2011, 10:27 AM #3
Banned
- Join Date
- Oct 2011
- Posts
- 34
- Rep Power
- 0
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
-
How to open Netbeans and run main class from command Line
By kamalkishore in forum NetBeansReplies: 0Last Post: 04-20-2011, 01:03 PM -
Error While Running Windows Command Line Instruction
By divs1210 in forum AWT / SwingReplies: 5Last Post: 04-13-2011, 05:09 PM -
Running Jar file using command line through Java Codes
By NaturalE in forum Advanced JavaReplies: 2Last Post: 02-24-2011, 05:07 AM -
"Could not find the main class" for Linux Command Line Compile
By tetelee in forum New To JavaReplies: 3Last Post: 08-25-2010, 11:21 AM -
Compiling/Running Project in Command Line: "Could not find main class" Error
By Yasemin Gokce in forum New To JavaReplies: 1Last Post: 06-30-2009, 03:32 PM
Bookmarks