简体   繁体   English

VS 代码 - 无法解析导入“#####”

[英]VS Code - The import "#####" cannot be resolved

So, i am running a java project which have many library that are available in the current working directory but VS code seems to not recognize these library and giving out error "The import ###### cannot be resolved" ex: The import org.apache.pdfbox.pdmodel.PDDocument cannot be resolved"因此,我正在运行一个 java 项目,该项目在当前工作目录中有许多可用的库,但 VS 代码似乎无法识别这些库并发出错误“导入 ###### 无法解析”,例如:导入org.apache.pdfbox.pdmodel.PDDocument 无法解析”

here is the image that might help you to know more about it This is the package that i am working on: Here the org/apache is the library contain the class file that are need to be imported and FileArrangement.java is the file having the import statements这是可以帮助您了解更多信息的图片这是我正在处理的 package:这里的 org/apache 是包含需要导入的 class 文件的库,FileArrangement.java 是具有进口声明

Error i have been receiving this is what VS code is been showing我收到的错误是 VS 代码显示的内容

i really need your help because i really don't have any idea how to correct this我真的需要你的帮助,因为我真的不知道如何纠正这个

I have checked other projects and they are also showing the same result although the import statements for java classes like.我检查了其他项目,它们也显示了相同的结果,尽管 java 类的导入语句类似。 java.util.ArrayList doesn't show any kind of error and i have tried to clean java in VS code it also didn't work java.util.ArrayList 没有显示任何类型的错误,我试图在 VS 代码中清理 java 它也没有用

i just need to correct this error of VS code to import the classes that i need No error on java.util package我只需要更正 VS 代码的这个错误即可导入我需要的类java.util package 上没有错误

Putting the libraries in your current working directory does not work for Java, you need to add them to the classpath.将库放在当前工作目录中对 Java 不起作用,您需要将它们添加到类路径中。

If you're using maven, that manages the classpath for you.如果您使用的是 maven,它会为您管理类路径。

If not, you can manage it in VS Code by executing the Java: Configure Classpath command from the Command Palette (Ctrl+Shift+P).如果没有,您可以通过从命令面板 (Ctrl+Shift+P) 执行Java: Configure Classpath命令在 VS Code 中管理它。

You can add dependencies via Referenced libraries under the JAVA PROJECTS panel.您可以通过JAVA PROJECTS面板下的Referenced libraries添加依赖项。

在此处输入图像描述

Or use java.project.referencedLibraries setting in settings.json .或者在settings.json中使用java.project.referencedLibraries设置。

For example:例如:

"java.project.referencedLibraries": [
    "library/**/*.jar",
    "/home/username/lib/foo.jar"
]

Details can be found in configure-classpath and manage-dependencies .可以在configure-classpathmanage-dependencies中找到详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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