简体   繁体   中英

VS Code Java problems

I have had this very annoying problem with my java project in VS Code.

My project is the folder project, and in it there is resources folder, src folder and some other files. in src I have some packages and in them I have my java code.

My java code is packaged as not in src ie the first line is:

package foo.bar.baz;

And not:

package src.foo.bar.baz;

And for some mindbending reason, VS Code cannot understand that it needs to run from within the src folder and it sends me a message to add project/src/foo/bar/baz/code.java to the path which is not what I want. I can skip it or apply it and if I skip it it doesn't run.

Even when I'm editing that settings.json source path to be the right one it doesn't go.

I cannot change the project's structure in any way and I am using the regular java extension pack with nothing else added.

I would love some help because it seems to happen randomly over project with similar structure.

Thanks!

Open Command Palette and choose Java: Clean Java Language Server Workspace . After that, right click the folder src and click Add Folder to Java Source Path , which is equivalent to add the following code in Settings.json:

"java.project.sourcePaths": [
        "src"
    ],

Then the code should work without errors: 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM