I need to run single java files independently in Intellij IDEA or vscode. Currently, when I run a single program both IDEs checks for other files.
For example, in the given image, I need to run ReversingString program only, but it doesn’t run it and asks me to correct error in other java files.
How can I run a single file while ignoring other files. I checked answers to other similar questions here like editing run configuration but nothing is working.
I want all files in this folder to be independent/separate from each other.
Update: I found the solution :
All you need to do is to basically stop building the project.
For that click beside the run icon – "Edit/Run configurations" Click on modify option and check the option "Do not build before run" and now you can run a single file.
2
Answers
To run single java independently in Intellij IDEA you’ve choices:
read the answers here for more details.
UPDATE:
This problem has been fixed in the latest version of vscode.
In VS Code, you only need to click
proceed
in the pop-up window to compile and run the current file normally.Below is my file structure, I open myproject folder in VS Code.
I have two errors in DemoTwo.java. When I run DemoOne.java, a pop-up window will appear. Click
proceed
to compile and run demoone normally.Another way:
Install the Code Runner extension, then right-click on the DemoOne.java editing interface and select
Run Code
( Ctrl + Alt + N ). This will run the code using Code Runner, it will not compile all the files in the folder. Output results directly on the OUTPUT panel.