如何避免VS Code警告:“ [myfile] .java是非项目文件,仅报告语法错误”。 [英] How to avoid VS Code warning: "[myfile].java is a non-project file, only syntax errors are reported"

查看:1494
本文介绍了如何避免VS Code警告:“ [myfile] .java是非项目文件,仅报告语法错误”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Visual Studio Code的Java项目中运行构建任务。
问题中的警告选项卡:

I am running a build task in a java project in Visual Studio Code. The warning in the "PROBLEMS" tab:


[myfile] .java是非项目文件,仅报告语法错误

[myfile].java is a non-project file, only syntax errors are reported

它是指我在包含main()的类文件中加载的第一行:

It refers to the first line where I load in the class file containing the main():

package [the project folder];
import [the project folder].[the file with other classes].*;



  • 我只能通过复制文件文本(代码文本本身)来避免警告放入新的不相关文件夹中的新项目的新Java文件中。代码本身是正确的,并且可以正确编译。实际上,这就是答案,但这是很多手工工作。

  • 当我仅将带有警告消息的项目的Java文件复制到新文件夹中时,警告仍然出现!! !! (!)

  • 当然,当我将整个项目文件夹复制到新位置时,错误仍然存​​在。

  • 我猜将文本复制到具有相同名称和文件夹结构的新Java文件中与复制文件本身不同,因为文件可能会被VS Code标记,因此即使在文件夹结构被破坏。也许这支持从恢复的原始文件恢复项目结构?

    I guess that copying text into new java files with the same names and the same folder structure is different from copying the files themselves because the files probably get tagged by VS Code, so that they have a project stamp even when the folder structure is destroyed. Perhaps this supports recovering the project structure from recovered raw files? Could this be the problem of this Visual Code warning?

    我之前检查过其他线程,这只是最后一步。

    I checked other threads before, this is just the last step.

    • How can I fix build failed, do you want to continue? in vscode
    • Visual Studio Code - Java - Import Errors and More

    ->因此,我清理了vscode的workspaceStorage(在Windows上: C:\Users\USER\AppData\Roaming\Code\User\workspaceStorage ),然后重新启动,

    --> Thus, I cleaned vscode's workspaceStorage (on Windows: C:\Users\USER\AppData\Roaming\Code\User\workspaceStorage) and restarted without success.

    推荐答案

    我也收到了同样的警告。仅仅是因为我在同一个vscode工作区中有两个Java项目。将projA移出工作区后,projB的警告就消失了。

    I got the same warning as well. It was simply because I had two Java projects in the same vscode workspace. Once I've moved projA out of the workspace, the warning is gone for projB.

    WorkspaceRoot
    │   projectA
    └───projectB
    

    在这一点上,我认为最可能的解决方案是针对一个Java(Maven)项目工作区。否则,我想vscode会将它们全部视为一个项目,并且彼此干扰。

    At this point, I think the most likely solution is to have one Java (Maven) project for one workspace. Otherwise I guess vscode will treat they all as one project and they'll interfere with each other.

    这篇关于如何避免VS Code警告:“ [myfile] .java是非项目文件,仅报告语法错误”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆