Good day. NetBeans when compiled, runs all .java files in one project. Is it possible to run only one .java file? I chose "Run File", but it still runs everything.

Here I am working with the second file, when compiling it launches the first one, even though it is closed in the editor.

example

  • 2
    Each program has its own launch point method main, and the launch revolves only around this method. but still you can save class - dirkgntly
  • @dDevil, then it turns out more correctly to create a new project every time? - Pollux
  • @dDevil, updated the first post. - Pollux
  • in the list of projects, select the desired project - right button - open properties - execution - main class - click the overview there and select the class that you need to run - dirkgntly
  • @dDevil, thanks! Make as the answer, I will note. - Pollux

1 answer 1

Each program has its own launch point, the main class with the main method, from which the main application thread starts. If the application has several such points, then the main class can be specified explicitly in several ways. To start the change of the main class at the IDE level.

To select a main class for an application with several classes containing the main start method, in the NetBeans IDE:

  1. Select a project in the list and click the right mouse button.

enter image description here

  1. The context menu is displayed, select Properties there.

enter image description here

  1. Next, the Properties window will open, go there to Run.

enter image description here

  1. Further in the Main class item there is a Browse button, on it and click, and select the class you need. Fix it with the Choose main class button and press Ok .

enter image description here

  1. Done!