Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
404 views
in Technique[技术] by (71.8m points)

java - How to run a NetBeans project in 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:

javac Main.java
      Sortchoice.java
      Selection.java
      SelectionSort.java
      Insertion.java
      InsertionSort.java
      Exchange.java
      ExchangeSort.java

(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 java.security.SecureClassLoader.defineCl...
at java.net.URLClassLoader.defineClass(URLC...
at java.net.URLClassLoader.access$000(URLCl...
at java.net.URLClassLoader$1.run(URLClassLo...
at java.security.AccessController.doPrivile... Method)
at java.net.URLClassLoader.findClass(URLCla...
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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...