You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect Package Warning even with correct folder structure #905
Hi Mithun Thomas (@mithun2003), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
VS Code’s Java extension (JDT LS) must know which folders are source roots. If you just open a folder containing src/Model, it treats the workspace root as the source folder and reports any package statement as mismatched. To fix:
Add a build descriptor (e.g. pom.xml or build.gradle) or a Eclipse .classpath file in your project root so JDT LS auto-detects src.
Or explicitly mark src as a source path in your settings.json:
"java.project.sourcePaths": [
"src"
]
After changing your project layout or settings, reload the Java language server instead of fully restarting VS Code:
Run Java: Clean the Java language server workspace from the Command Palette, then reopen the project.
Ensure you open the folder that contains src, not src itself, as your workspace root.
The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!
This issue has been closed automatically because it needs more information and has not had recent activity. Please reach out if you have or find the answers we need so that we can investigate further.
Activity
github-actions commentedon Sep 17, 2025
Hi Mithun Thomas (@mithun2003), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
src/Model, it treats the workspace root as the source folder and reports anypackagestatement as mismatched. To fix:pom.xmlorbuild.gradle) or a Eclipse.classpathfile in your project root so JDT LS auto-detectssrc.srcas a source path in your settings.json:src, notsrcitself, as your workspace root.Duplicate of:
Package name not recognized when opening standalone java files eclipse-jdtls/eclipse.jdt.ls#1764
Other references with low confidence
Package containing dot character not being parsed correctly redhat-developer/vscode-java#1406
[Java] The declared package "com.github.****" does not match the expected package "" redhat-developer/vscode-java#274 (comment)
The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!
mithun2003 commentedon Sep 17, 2025
Thanks for the quick reply. I’ve already tried the suggested steps:
My
settings.jsonalready contains:I am opening the project root (the folder containing src/, not src directly).
I also tried Java: Clean the Java language server workspace from the command palette, but the problem still persists.
The issue remains:
When I create or open a file inside src/Model/, VS Code shows Incorrect Package under package Model;.
The error disappears only after restarting VS Code, which suggests it’s not picking up source paths properly until restart.
So this doesn’t seem to be just a configuration issue, but possibly a bug in the Java Language Server’s handling of new files/folders without restart.
DonPalwo commentedon May 27, 2026
Did not work for me. Almost spend the half day on it .... moving to Netbeans
chagong commentedon Jun 10, 2026
Mithun Thomas (@mithun2003) can you share the extension versions of your"Extension Pack for Java" and "Language Support for Java by Red hat"?
DonPalwo, do you see the exact the same error? Would you like to share your extension versions?
github-actions commentedon Jul 11, 2026
This issue has been closed automatically because it needs more information and has not had recent activity. Please reach out if you have or find the answers we need so that we can investigate further.