eclipse 无效的类路径容器:将项目汇入vscode时,项目'Project'中的'JUnit 5'

kyvafyod  于 2022-11-04  发布在  Eclipse
关注(0)|答案(1)|浏览(283)

我从github得到了这个java项目,因为它要完成一个任务。它在Eclipse中工作得很好,但是当在vscode中运行时,我在“问题”下收到了两个错误:
"The project cannot be built until build path errors are resolved"
"The project cannot be built until build path errors are resolved"
我发现eclipse和vscode之间的唯一区别是eclipse使用它自己的(?)JRE,而vscode使用微软的
当我继续运行该项目时,我得到错误:
Cannot invoke "org.eclipse.jdt.core.IClasspathEntry.getEntryKind()" because "cpe" is null
当我打开日志时,第一条错误消息是

!MESSAGE Error
!STACK 0
java.io.FileNotFoundException: org.eclipse.equinox.simpleconfigurator/bundles.info (No such file or directory)
    at java.base/java.io.FileInputStream.open0(Native Method)
    at java.base/java.io.FileInputStream.open(FileInputStream.java:216)
    at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
    at java.base/java.io.FileInputStream.<init>(FileInputStream.java:111)
    at java.base/sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:86)
    at java.base/sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:189)
    at java.base/java.net.URL.openStream(URL.java:1161)
    at org.eclipse.equinox.internal.simpleconfigurator.manipulator.SimpleConfiguratorManipulatorImpl.loadConfiguration(SimpleConfiguratorManipulatorImpl.java:365)
    at org.eclipse.jdt.internal.junit.buildpath.P2Utils.findBundle(P2Utils.java:93)
    at org.eclipse.jdt.internal.junit.buildpath.BuildPathSupport$JUnitPluginDescription.getBundleLocation(BuildPathSupport.java:89)
    at org.eclipse.jdt.internal.junit.buildpath.BuildPathSupport$JUnitPluginDescription.getBundleLocation(BuildPathSupport.java:85)
    at org.eclipse.jdt.internal.junit.buildpath.BuildPathSupport$JUnitPluginDescription.getLibraryEntry(BuildPathSupport.java:207)
    at org.eclipse.jdt.internal.junit.buildpath.BuildPathSupport.getJUnitJupiterApiLibraryEntry(BuildPathSupport.java:430)
    at org.eclipse.jdt.internal.junit.buildpath.JUnitContainerInitializer.getNewContainer(JUnitContainerInitializer.java:125)
    at org.eclipse.jdt.internal.junit.buildpath.JUnitContainerInitializer.initialize(JUnitContainerInitializer.java:101)
    at org.eclipse.jdt.internal.core.JavaModelManager.initializeContainer(JavaModelManager.java:3145)
    at org.eclipse.jdt.internal.core.JavaModelManager.getClasspathContainer(JavaModelManager.java:2093)
    at org.eclipse.jdt.core.JavaCore.getClasspathContainer(JavaCore.java:3789)
    at org.eclipse.jdt.internal.core.JavaProject.resolveClasspath(JavaProject.java:3270)
    at org.eclipse.jdt.internal.core.JavaProject.resolveClasspath(JavaProject.java:3434)
    at org.eclipse.jdt.internal.core.JavaProject.getResolvedClasspath(JavaProject.java:2519)
    at org.eclipse.jdt.internal.core.ExternalFoldersManager.refreshReferences(ExternalFoldersManager.java:494)
    at org.eclipse.jdt.internal.core.DeltaProcessor.resourceChanged(DeltaProcessor.java:2091)
    at org.eclipse.jdt.internal.core.DeltaProcessingState.resourceChanged(DeltaProcessingState.java:501)
    at org.eclipse.core.internal.events.NotificationManager$1.run(NotificationManager.java:307)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.core.internal.events.NotificationManager.notify(NotificationManager.java:297)
    at org.eclipse.core.internal.events.NotificationManager.handleEvent(NotificationManager.java:279)
    at org.eclipse.core.internal.resources.Workspace.broadcastEvent(Workspace.java:383)
    at org.eclipse.core.internal.resources.Resource.refreshLocal(Resource.java:1572)
    at org.eclipse.core.internal.resources.Project.open(Project.java:1094)
    at org.eclipse.jdt.ls.core.internal.managers.EclipseProjectImporter.importDir(EclipseProjectImporter.java:130)
    at org.eclipse.jdt.ls.core.internal.managers.EclipseProjectImporter.lambda$4(EclipseProjectImporter.java:100)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at org.eclipse.jdt.ls.core.internal.managers.EclipseProjectImporter.importToWorkspace(EclipseProjectImporter.java:100)
    at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.importProjects(ProjectsManager.java:149)
    at org.eclipse.jdt.ls.core.internal.managers.ProjectsManager.initializeProjects(ProjectsManager.java:111)
    at org.eclipse.jdt.ls.core.internal.handlers.InitHandler$1.runInWorkspace(InitHandler.java:244)
    at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)```
axzmvihb

axzmvihb1#

JUnit 5容器应该是在Eclipse中创建和配置的lib容器,其中的信息存储在Eclipse IDE中。因此,VS代码无法恢复它。
作为一种解决方法,您可以打开项目的.classpath,找到容器Junit 5的条目,将其删除。然后添加JUnit 5依赖项,如下所示:

<classpathentry kind="lib" path="xxx/xxx/junit-platform-console-standalone-1.9.0.jar" sourcepath="xxx/xxx/junit-platform-console-standalone-1.9.0-sources.jar"/>

sourcepath是可选的,具体取决于您是否要检查库的源代码。
或者,如果您的任务不限于作为Eclipse项目完成,则可以在VS代码中创建一个新的非托管文件夹项目:请选择“No build tools”。
并启用测试框架:https://code.visualstudio.com/docs/java/java-testing#_enable-testing-and-adding-test-framework-jars-to-your-project

相关问题