Home > Software design >  Invalid classpath container: 'JUnit 5' in project 'Project' when importing proje
Invalid classpath container: 'JUnit 5' in project 'Project' when importing proje

Time:08-06

I got this java project from github as it was to be completed for an assignment. It works fine in Eclipse, however when running in vscode I receive the two errors under "Problems":

"Invalid classpath container: 'JUnit 5' in project 'projectName'"

"The project cannot be built until build path errors are resolved"

The only difference I've found between eclipse and vscode is that eclipse uses its own(?) JRE, while vscode uses the microsoft17

When i proceed to run the project I get the error:

Cannot invoke "org.eclipse.jdt.core.IClasspathEntry.getEntryKind()" because "cpe" is null

When I open the log the first error message is

!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)```

CodePudding user response:

The JUnit 5 container should be a lib container that you created and configured in Eclipse, where the information is stored in the Eclipse IDE. Thus, VS Code could not recover it.

As a workaround, you can open the .classpath of your project, find the entry of the container Junit 5, remove it. And add JUnit 5 dependencies like this:

<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"/>

The sourcepath is optional depending on whether you want to check the sources of the lib or not.

Or, if your assignment is not limited to be completed as an Eclipse project, you can create a new unmanaged folder project in VS Code: https://code.visualstudio.com/docs/java/java-project#_create-a-new-java-project, select No build tools.

And enable the testing framework: https://code.visualstudio.com/docs/java/java-testing#_enable-testing-and-adding-test-framework-jars-to-your-project

  • Related