How do I run a NetBeans project in the command prompt?


My professor asked us to create a Java program that would be able to run in command prompt but could also be opened using NetBeans.

The program is about using the different types of sorting (specifically Selection, Insertion, Exchange, Quick, and Heap sorting). our professor specifically told us to use object oriented programming in Java, and that she wants to see a main class plus the different classes that would do the sorting.

I tried to write the program in NetBeans — thinking that later I could simply run the program in cmd using javac.

In cmd, I typed the path where my NetBeans project was saved and I tried to compile the files using javac. but it says that "'javac' is not recognized as an internal or external command, operable program or batch file."

So I tried to save the files in sun>sdk>jdk>bin, and from there I tried to compile the files, and it was fine. The problem sets in when I tried to run them.

Here's how I tried to compile the files:


(I havent finished the syntax for the next two sorting.)

Here's how I tried to run the files in cmd:

java Main Sortchoice Selection SelectionSort Insertion InsertionSort Exchange ExchangeSort

and cmd says:

exception in thread "main" java.lang.NoClassDefFoundError: main (wring name: myjava/Main)
at java.lang.ClassLoader.defineClass1(Nativ... Method)"
at java.lang.ClassLoader.defineClass(ClassL...
at Method)
at java.lang.ClassLoader.loadClass(ClassLoa...
at sun.misc.Launcher&AppClassLoader.loadCla...
at java.lang.ClasLoader.loadClass(ClassLoad...
at java.lang.ClassLoader.loadClassInternal(...

What should I do? (Sorry for my kilometric-long explanation. I just wanted to put in as many details as possible.)

I would also like to emphasize that I'm just a beginner in Java programming.

If you click build inside NetBeans, it should give you (in your compiler output) a message like, "To run this application from the command line without Ant, try: java -jar yourPathToRun"