I have always run Main from an IDEA. How do I run Main from command line
Printable View
I have always run Main from an IDEA. How do I run 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!
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.