Skip to content

"Run Test with coverage" doesn't work: "Could not find or load main class" #1714

Closed

Description

Coverage testing isn't working for me. When I run with coverage, the progress monitor spins indefinitely and no coverage information is provided. The test results are displayed correctly if I run without coverage.

I'm seeing the following error in the extension host logs:

Error: Could not find or load main class \-javaagent:c:\\\\Users\\\\myusername\\\\.vscode\\\\extensions\\\\vscjava.vscode-java-test-0.41.1\\\\server\\\\jacocoagent.jar=destfile=c:\\\\Users\\\\myusername\\\\AppData\\\\Roaming\\\\Code\\\\User\\\\workspaceStorage\\\\df684810f26c0547aff1b945ce0cc0fc\\\\vscjava.vscode-java-test\\\\my-project\\\\coverage\\\\jacoco.exec\\ Caused by: java.lang.ClassNotFoundException: \-javaagent:c:\\\\Users\\\\myusername\\\\.vscode\\\\extensions\\\\vscjava.vscode-java-test-0.41.1\\\\server\\\\jacocoagent.jar=destfile=c:\\\\Users\\\\myusername\\\\AppData\\\\Roaming\\\\Code\\\\User\\\\workspaceStorage\\\\df684810f26c0547aff1b945ce0cc0fc\\\\vscjava.vscode-java-test\\\\my-project\\\\coverage\\\\jacoco.exec\\

vscode-java-test Extension version: 0.41.1
VS Code Version:
Version: 1.91.1
Commit: f1e16e1e6214d7c44d078b1f0607b2388f29d729
Electron: 29.4.0
ElectronBuildId: 9728852
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Windows_NT x64 10.0.19045

Activity

  1. jdneo commented on Jul 25, 2024

    @jdneo
    Member

    Is there any error log in the server log? (Trigger Java: Open Java Language Server Log File)

    Is it possible to share a sample project to us?

  2. LeonardoBevilacqua commented on Jul 25, 2024

    @LeonardoBevilacqua
    Author

    Here is the log

    !ENTRY org.eclipse.jdt.ls.core 4 2 2024-07-25 09:13:51.207
    !MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jdt.ls.core".
    !STACK 0
    java.io.FileNotFoundException: c:\Users\myusername\AppData\Roaming\Code\User\workspaceStorage\df684810f26c0547aff1b945ce0cc0fc\vscjava.vscode-java-test\my-project\coverage\jacoco.exec (The system cannot find the path specified)
    	at java.base/java.io.FileInputStream.open0(Native Method)
    	at java.base/java.io.FileInputStream.open(Unknown Source)
    	at java.base/java.io.FileInputStream.<init>(Unknown Source)
    	at org.jacoco.core.tools.ExecFileLoader.load(ExecFileLoader.java:72)
    	at com.microsoft.java.test.plugin.coverage.CoverageHandler.getCoverageDetail(CoverageHandler.java:82)
    	at com.microsoft.java.test.plugin.handler.TestDelegateCommandHandler.executeCommand(TestDelegateCommandHandler.java:85)
    	at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler$1.run(WorkspaceExecuteCommandHandler.java:230)
    	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    	at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler.executeCommand(WorkspaceExecuteCommandHandler.java:220)
    	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$4(JDTLanguageServer.java:604)
    	at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)
    	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)
    	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(Unknown Source)
    	at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
    	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
    	at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
    	at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
    	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
    
    !ENTRY org.eclipse.jdt.ls.core 4 0 2024-07-25 09:13:51.208
    !MESSAGE Error in calling delegate command handler
    !STACK 0
    java.io.FileNotFoundException: c:\Users\myusername\AppData\Roaming\Code\User\workspaceStorage\df684810f26c0547aff1b945ce0cc0fc\vscjava.vscode-java-test\my-project\coverage\jacoco.exec (The system cannot find the path specified)
    	at java.base/java.io.FileInputStream.open0(Native Method)
    	at java.base/java.io.FileInputStream.open(Unknown Source)
    	at java.base/java.io.FileInputStream.<init>(Unknown Source)
    	at org.jacoco.core.tools.ExecFileLoader.load(ExecFileLoader.java:72)
    	at com.microsoft.java.test.plugin.coverage.CoverageHandler.getCoverageDetail(CoverageHandler.java:82)
    	at com.microsoft.java.test.plugin.handler.TestDelegateCommandHandler.executeCommand(TestDelegateCommandHandler.java:85)
    	at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler$1.run(WorkspaceExecuteCommandHandler.java:230)
    	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    	at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler.executeCommand(WorkspaceExecuteCommandHandler.java:220)
    	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$4(JDTLanguageServer.java:604)
    	at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)
    	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)
    	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(Unknown Source)
    	at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
    	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
    	at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
    	at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
    	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
    

    unfortunately, I cannot share a sample of the project.

    Additional notes: I used to run the code in another IDE without any problem, recently tried in VSCode with the JAVA Pack extension. Everything worked fine out of the box, running, debugging and testing without issues, only the coverage action doesn't work, but I can run the mvn command to generate the report.

  3. jdneo commented on Aug 1, 2024

    @jdneo
    Member

    Leonardo Bevilacqua (@LeonardoBevilacqua) Is this still a problem in 0.42.0?

  4. LeonardoBevilacqua commented on Aug 5, 2024

    @LeonardoBevilacqua
    Author

    Yes, the still a problem

  5. jdneo commented on Aug 6, 2024

    @jdneo
    Member

    What's the jacoco version used in your project?

  6. jdneo commented on Aug 7, 2024

    @jdneo
    Member

    I'm guessing that this might be caused by the version of jacoco agent of the project is different from the embedded one in extension.

    In #1723, I changed to implementation that using the one from project if it's available.

    Would you mind trying the pre-release 0.42.2024080609 and let me know if the issue is fixed or not?

  7. LeonardoBevilacqua commented on Aug 7, 2024

    @LeonardoBevilacqua
    Author

    I've tried the pre-release version, still does not work. I believe the jacoco version is 0.8.10, (not managed by my current project)

    Edit: I tried with 2 projects, both with the same issue

  8. LoveraSantiago commented on Sep 9, 2024

    @LoveraSantiago

    Hello.
    I was facing this problem too.
    As recomended by Sheng Chen (@jdneo) I've tried the pre-release 0.42.2024080609 and the problem still persist.

    Here we use an internal and "non-sense" framework wich brings jacoco 0.8.8 .
    I've update the current project to force to bring recent version of jacoco 0.8.12.

    I could find a workaround copying the jacoco.exec of the current project found it in your-current-application>target>jacoco.exec to the folder where vscode complains about ClassNotFoundException on your case "-javaagent:c:\\Users\\myusername\\.vscode\\extensions\\vscjava.vscode-java-test-0.41.1\\server\\jacocoagent.jar=destfile=c:\\Users\\myusername\\AppData\\Roaming\\Code\\User\\workspaceStorage\\df684810f26c0547aff1b945ce0cc0fc\\vscjava.vscode-java-test\\my-project\\coverage\\jacoco.exec\"

    As Sheng Chen (@jdneo) points out. Its something with conflict version.

    Anyway thanks. I love to work with the vscode.

  9. jdneo commented on Sep 10, 2024

    @jdneo
    Member

    Santuga Lovera (@LoveraSantiago) Would you mind sharing the project that having this issue?

  10. mdima commented on Nov 4, 2024

    @mdima

    Same here, just I cannot share so much of this project :S

    When I run a test with coverage I receive this error:

    
    Error: Could not find or load main class \-javaagent:c:\\\\Users\\\\michele.dimaria\\\\.vscode\\\\extensions\\\\vscjava.vscode-java-test-0.42.0\\\\server\\\\jacocoagent.jar=destfile=c:\\\\Users\\\\michele.dimaria\\\\AppData\\\\Roaming\\\\Code\\\\User\\\\workspaceStorage\\\\dff81ef8239cb1c05fbfcd6bbde7cebc\\\\vscjava.vscode-java-test\\\\uibm-persistance-importer\\\\coverage\\\\jacoco.exec\\
    Caused by: java.lang.ClassNotFoundException: \-javaagent:c:\\\\Users\\\\michele.dimaria\\\\.vscode\\\\extensions\\\\vscjava.vscode-java-test-0.42.0\\\\server\\\\jacocoagent.jar=destfile=c:\\\\Users\\\\michele.dimaria\\\\AppData\\\\Roaming\\\\Code\\\\User\\\\workspaceStorage\\\\dff81ef8239cb1c05fbfcd6bbde7cebc\\\\vscjava.vscode-java-test\\\\uibm-persistance-importer\\\\coverage\\\\jacoco.exec\\
    
  11. sansovic commented on Nov 28, 2024

    @sansovic

    Same issue here with version 0.43.0.
    !ENTRY org.eclipse.jdt.ls.core 4 2 2024-11-28 19:33:31.931
    !MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jdt.ls.core".
    !STACK 0
    java.io.FileNotFoundException: c:\Users\Guille\AppData\Roaming\Code\User\workspaceStorage\9f172f0711175a75b35aa3050c275a0c\vscjava.vscode-java-test\service\coverage\jacoco.exec (The system cannot find the path specified)
    at java.base/java.io.FileInputStream.open0(Native Method)
    at java.base/java.io.FileInputStream.open(Unknown Source)
    at java.base/java.io.FileInputStream.(Unknown Source)
    at org.jacoco.core.tools.ExecFileLoader.load(ExecFileLoader.java:72)
    at com.microsoft.java.test.plugin.coverage.CoverageHandler.getCoverageDetail(CoverageHandler.java:82)
    at com.microsoft.java.test.plugin.handler.TestDelegateCommandHandler.executeCommand(TestDelegateCommandHandler.java:85)
    at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler$1.run(WorkspaceExecuteCommandHandler.java:230)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    at org.eclipse.jdt.ls.core.internal.handlers.WorkspaceExecuteCommandHandler.executeCommand(WorkspaceExecuteCommandHandler.java:220)
    at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$4(JDTLanguageServer.java:610)
    at org.eclipse.jdt.ls.core.internal.BaseJDTLanguageServer.lambda$0(BaseJDTLanguageServer.java:87)
    at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source)
    at java.base/java.util.concurrent.CompletableFuture$Completion.exec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)

    This is on a freshly installed Windows 11 Pro machine. I have the same issue on a different Windows 11 Pro laptop but not on a MacBook Air, always on the exact same project.

    The issue on Windows affects all the projects I tried.

    I cannot share files but I can run tests if it helps.

  12. YuyaYokoyama8864 commented on Dec 24, 2024

    @YuyaYokoyama8864

    It didn't work in my environment either, but I removed the double quotation marks on line 75 of src/utils/launchUtils.ts and loaded the vsix I made with it and it worked.

  13. sansovic commented on Dec 24, 2024

    @sansovic

    It didn't work in my environment either, but I removed the double quotation marks on line 75 of src/utils/launchUtils.ts and loaded the vsix I made with it and it worked.

    That was it. Thank you so much!

  14. added 3 commits that reference this issue on Dec 26, 2024
  15. leafriend commented on Jan 17, 2025

    @leafriend

    thanks YuyaYokoyama8864 .

    1. download .vsix file
    2. unzip it
    3. open extension/dist/extension.bundle.js
    4. replace "win32"===o.platform()&&(e=`"${e}"`)
      to "win32"===o.platform()&&(e=`${e}`) (remove double quotation)
    5. zip and change extension to .vsix
    6. install edited vsix
    7. it works for me
  16. github-actions commented on Nov 12, 2025

    @github-actions

    Hi Leonardo Bevilacqua (@LeonardoBevilacqua), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.

    Suggestions:

    If the above does not help, please file an issue at https://github.com/microsoft/vscode-java-test/issues with the java.test.logLevel output and your launch.json/project setup.

    Other references with low confidence

    The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!

  17. Creat1veM1nd commented on Feb 3, 2026

    @Creat1veM1nd

    thanks @YuyaYokoyama8864 .

    1. download .vsix file
    2. unzip it
    3. open extension/dist/extension.bundle.js
    4. replace "win32"===o.platform()&&(e=`"${e}"`)
      to "win32"===o.platform()&&(e=`${e}`) (remove double quotation)
    5. zip and change extension to .vsix
    6. install edited vsix
    7. it works for me

    This worked for me with using 0.44.0 - I wonder why this issue isn't fixed already a year later. Any plans to do so in near future ?

    Btw. this AI answer did not work for me at all.

  18. mdima commented on Feb 3, 2026

    @mdima

    I applied the change live in my .vscode folder, it worked immediately.
    I hope this fix will be included in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions