英文:
How do I fix a “declared package does not match the expected package” error on VSCode
问题
我有一个 Gradle 项目:
.
|-- src
| |-- java
| | +-- myproj
| | +-- App.java
| +-- test
|-- build.gradle
+-- ...
App.java
文件内容如下:
package myproj;
// ^^^^^^ 错误信息
但是 VSCode 告诉我“声明的包“myproj”与预期的包“main.java.myproj”不匹配”。我知道这与文件路径有关,但是我没有找到如何进行配置。
我已经安装了 Java Extension Pack 插件,接下来我该怎么办?
附注:我不希望配置方案过于复杂,我只是在写一个非常小的程序。最好能在 setting.json
中完成。
英文:
I have a gradle project:
.
|-- src
| |-- java
| | +-- myproj
| | +-- App.java
| +-- test
|-- build.gradle
+-- ...
and App.java
file looks like this:
package myproj;
// ^^^^^^ error message
but VSCode tells me “The declared package "myproj" does not match the expected package "main.java.myproj"”. I know this is related to the file path, but I did not find out how to configure it.
I have installed the Java Extension Pack plug-in, what should I do next?
PS. I don’t want the configuration scheme to be too complicated, I’m just writing a very small program. It is best to be able to complete in setting.json
.
答案1
得分: 1
尝试在src和java文件夹之间添加“main”目录,以匹配Gradle的文件夹结构。
来源:https://docs.gradle.org/current/userguide/organizing_gradle_projects.html
英文:
Try to add "main" directory between src and java folder to match gradle folders structure.
Source: https://docs.gradle.org/current/userguide/organizing_gradle_projects.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论