skip to Main Content

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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search