java cmd net use,如何在命令提示符下运行NetBeans项目?

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.

解决方案

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"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值