0

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.

Error

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.

SHIV1198
  • 57
  • 2
  • 5
  • Please see https://stackoverflow.com/a/16784855/12844632 – Egor Klepikov Nov 01 '22 at 08:46
  • @JialeDu I am trying to run only ReversingString file/class but the IDE is building/compiling all the classes in that folder. So I have to correct all the errors in other files (if any) before I can run a pacticular file which I dont want. I want to run only one class not bothering about others. – SHIV1198 Nov 01 '22 at 16:07
  • This can be fixed with [microsoft/java-debug#459](https://github.com/microsoft/java-debug/pull/459). – JialeDu Nov 18 '22 at 09:04

2 Answers2

1

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.

myproject
├─ DemoOne.java
└─ DemoTwo.java

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.

enter image description here

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.

enter image description here

JialeDu
  • 6,021
  • 2
  • 5
  • 24
  • Yes it works in VS code. Though the problem is the same, it builds the whole project and prompts us to fix errors but we can still click Proceed and run a single file. – SHIV1198 Dec 13 '22 at 07:59
  • This problem has been fixed in the latest version. – JialeDu Dec 13 '22 at 08:05
0

To run single java independently in Intellij IDEA you've choices:

  • Right-click somewhere in the editing area and select Run 'ReversingString.main()'.
  • Open the file in editor and use Ctrl+Shift+F10

read the answers here for more details.

Oth Mane
  • 1
  • 3