How to run a NetBeans project in command prompt?

后端 未结 8 984
挽巷
挽巷 2020-12-14 19:51

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 di

8条回答
  •  隐瞒了意图╮
    2020-12-14 20:21

    The easiest way to do this is to run the .jar file in the dist folder under your project's main folder. Make sure the path to the jdk bin folder in your computer's System, Environmental Variables is set to find the usual: jar.exe, java.exe, javac.exe, etc, (see other posts in this thread if you need instructions on doing that).

    1) In Netbeans do a clean build, press F11 or click on the Run menu and click on Build Project. Click through to get past all the prompts, you need a clean build to do this.

    2) in the command prompt navigate to your project's dist folder

    3) on the command line type in and run: java -jar yourMainFile.jar

    No creating separate folders, no copying files, no multiple files to include on the command line argument. But you will have to re-build your project each time you change your code before running it on the command line.

提交回复
热议问题