Search code examples
javavisual-studio-codecompilationoutputsettings

When I run my .java projects, the compiler places the .class files in the src folder and in the bin folder


I'm having a problem with my output settings for my .java programs. Every time I click on the button to run my project, the compiler creates the .class files and throws them into src, while it also throws them into bin. Wouldn't it be right to put these .class files only in bin and leave the src folder "clean" (only with the .java files)? How can I fix this?

I saw a question similar to mine (Visual Studio Code puts .class files in src folder when compiling), but the settings are correct, but the error is still there. My VS Workspace: https://i.sstatic.net/ONPIJ.png


Solution

  • It can be seen by screenshots that you are using CodeRunner to execute the code, so the .class file will be generated directly in the same level of the script file.

    Please use the Java extension package to execute the script, so that the "java.project.outputPath": "bin" settings will be used.

    enter image description here

    The verification method is to delete all the existing .class files, and then use Java extension toexecute the script. You will see that the class file is generated under the bin folder.

    https://code.visualstudio.com/docs/java/java-tutorial

    Of course, I also suggest that you do not use CodeRunner first. Only the official extensions in the early stage will avoid a lot of trouble. Because there are many settings and configurations that are brought about by official extensions, CodeRunner only uses commands to run scripts.