VSCode无法导入外部库

时间:2019-07-28 18:02:46

标签: java visual-studio-code importerror java-11

我目前正在尝试学习VSCode。我现在正在使用VSCode在Java 11中进行编程。在下面的示例代码中,有4行导入。他们中的前两个正在工作。但是其中的下两个出现了以下错误。

package app;

import java.util.*;
import java.awt.*;
import com.google.common.primitives.Ints;
import org.apache.commons.collections.iterators.ArrayIterator;

/**
 * Board_Space
 */
public class Board_Space {


}
"The import com.google cannot be resolved. Java(268435846) [5,8]"
"The import org.apache.commons.collections cannot be resolved. Java(268435846) [6,8]"

如何解决此错误以及如何使用任何种类的外部库?

Related Environment Info:

 - OS: Windows 10
 - JDK 11 is installed. JAVA_HOME and PATH environment variables are set.
 - apache-maven-3.6.1 is installed. MAVEN_HOME and M2_HOME environment variables are set.
 - VSCode Version: 1.36.1 (user setup) 
 - VSCode Commit: 2213894ea0415ee8c85c5eea0d0ff81ecc191529


Extensions:

 - Name: Checkstyle for Java / Id: shengchen.vscode-checkstyle
 - Name: Code Spell Checker / Id: streetsidesoftware.code-spell-checker
 - name: Debugger for Java / Id: vscjava.vscode-java-debug
 - Name: Java Dependency Viewer / Id: vscjava.vscode-java-dependency
 - Name: Java Extension Pack / Id: vscjava.vscode-java-pack
 - Name: Java Test Runner / Id: vscjava.vscode-java-test
 - Name: Language Support for Java(TM) by Red Hat / Id: redhat.java
 - Name: Maven for Java / Id: vscjava.vscode-maven
 - Name: Visual Studio IntelliCode / Id: visualstudioexptteam.vscodeintellicode

1 个答案:

答案 0 :(得分:1)

添加必须更改库的maven或gradle Generated data binding class includes androids support library's classes文件之外的外部Jar文件。

1。在项目内部创建一个名为.classpath的文件夹,并将您的lib文件添加到其中

2。在.jar中配置路径,例如:

.classpath

3。如果仍然出现错误,请清理工作空间目录:<classpathentry kind="lib" path="lib/xxxx.jar"/> -输入F1-Clean

enter image description here enter image description here