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

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

问题描述

我的教授要求我们创建一个 Java 程序,它可以在命令提示符下运行,但也可以使用 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.

该程序是关于使用不同类型的排序(特别是选择、插入、交换、快速和堆排序).我们的教授特别告诉我们在 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.)

我还要强调,我只是 Java 编程的初学者.

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

推荐答案

如果您在 NetBeans 中单击构建,它应该给您(在您的编译器输出中)一条消息,例如要在没有 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天全站免登陆