如何在命令提示符下运行NetBeans项目? [英] How to run a NetBeans project in command prompt?

查看:553
本文介绍了如何在命令提示符下运行NetBeans项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的教授要求我们创建一个能够在命令提示符下运行但也可以使用NetBeans打开的Java程序。

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.

程序是关于使用不同类型的排序(特别是选择,插入,交换,快速和堆排序)。我们的教授专门告诉我们在Java中使用面向对象的编程,她希望看到一个主类以及可以进行排序的不同类。

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.

我试图在NetBeans中编写程序 - 以为我稍后可以使用javac在cmd中运行程序。

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

在cmd中,我输入了NetBeans项目保存的路径,尝试使用javac编译文件。但它说'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."

所以我试图保存文件在sun> sdk> jdk> bin,从那里我试图编译文件,这是很好。

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.)

这是我尝试在cmd中运行文件的方式:

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

java Main Sortchoice Selection SelectionSort Insertion InsertionSort Exchange ExchangeSort

和cmd说:

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.

推荐答案

如果您在NetBeans中单击build,它应该给您(在您的编译器输出中) 要在没有Ant的情况下从命令行运行此应用程序,请尝试:
java -jar yourPathToRun

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"

这篇关于如何在命令提示符下运行NetBeans项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆