Skip to content

Debugging standalone Java files in VSCode returns ClassNotFoundException #344

Closed

Description

When the users open pure Java files in VSCode, and debug it, sometimes they get ClassNotFoundException. But if they remove the workspace cache or open all relevant .java files in Editor, the issue disappears.

This issue is involved with single file support. Currently we use a default project jdt.ls-java-project to link the pure Java files, it looks like the link mechanism is error-prone.

Below comments are copied from Gitter chat room.

CJ Bailey CJ Bailey (@cjbailey) Jul 25 17:50
Hi all. I had this extension working perfectly yesterday but today I keep getting the "class not found" exception (nothing has changed since yesterday). Now I can't even uninstall the extension, it just seems to hang.

CJ Bailey CJ Bailey (@cjbailey) Jul 25 18:02
ok, so that's interesting. Finally managed to uninstall and re-install the Java extension pack (including debugger), but still kept getting various class not found exceptions when trying to run the code. It turns out, if I open up all the relevant .java files in the editor first and then hit F5, it works!

CJ Bailey CJ Bailey (@cjbailey) 23:05
I am finding that many times when I get the "cannot find main class" error, deleting the workspace cache and re-opening VS Code seems to get rid of it (normally then revealing different errors in my code, which I'm not even sure are my fault or not - being the noob to Java that I am).

CJ Bailey CJ Bailey (@cjbailey) 23:11
For info, I'm trying not to use Maven or Gradle to begin with. I prefer the unadulterated Java experience while I'm learning the basics tbh.

Activity

  1. testforstephen commented on Jul 27, 2018

    @testforstephen
    ContributorAuthor

    cjbailey commented 11 hours ago
    I get this error quite a lot. I'm not sure if this is related but I often get errors such as this:

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    The method transform(TransformationInput, TransformationOutput) from the type CustomFieldMapping refers to the missing type StreamTransformationException

    But then if I open the missing class in the editor and hit F5 again the error seems to get resolved.

  2. testforstephen commented on Jul 27, 2018

    @testforstephen
    ContributorAuthor

    Yaohai Zheng (@yaohaizh) Please have a look at the single file support.

  3. Eskibear commented on Aug 27, 2018

    @Eskibear
    Member

    I think we must clarify the scope of the single file support.

    For me, I think it only provides convenience when you want to test some simple functions. You want to do some simple jobs, and you don't want to create a complex project, so you create a .java file and want to run it. Whenever you have more than one .java file, you should create a project to organize them, then the single file support should not apply any more.

    But then if I open the missing class in the editor and hit F5 again the error seems to get resolved.
    So this behavior introduces confusion. According to my understanding, even if the user open all the missing classes, the F5 should not work. Since the user has multiple classes working together, the right way is to create a project for them.

    Jinbo Wang (@testforstephen) Yaohai Zheng (@yaohaizh) What do you think?

  4. cjbailey commented on Aug 27, 2018

    @cjbailey

    I guess it might help if I gave a little background to this.

    I'm a SAP PI developer by trade and needed to create a complex mapping that necessitated the creation of a Java class to handle it. SAP doesn't exactly do a great job of facilitating this process (good old SAP!) and I wanted a quick and easy/dirty way to unit test the functionality so I turned to VS Code (cos I love it for Node.js development). I had to basically mock a load of classes that SAP requires which is the only reason I have multiple files, otherwise my 'project' is a single Java file. Hence I was trying to avoid having to create a full blown project (and I couldn't get Maven working anyway but that's another story).

    Hope that helps.

  5. michael-hawker commented on Oct 11, 2018

    @michael-hawker

    This is a pain for EDU scenarios too, it'd be great if a student can just open up a Java file and be able to run it and debug it without having to have a whole project system setup yet.

  6. removed this from the 0.12.0 milestone on Oct 12, 2018
  7. GorvGoyl commented on Oct 21, 2018

    @GorvGoyl

    is there any update on this? It's really frustrating when you quickly want to test some java code and you just can't do that.
    I don't want to set up the whole maven/gradle/eclipse project to test 5-10 lines of code. An extension should support the basic things first.

  8. changed the title [-]Debugging pure Java files in VSCode returns ClassNotFoundException[/-] [+]Debugging standalone Java files in VSCode returns ClassNotFoundException[/+] on Oct 22, 2018
  9. testforstephen commented on Oct 22, 2018

    @testforstephen
    ContributorAuthor

    @JerryGoyal The solution is still on discuss, see the issue update on the language server side. redhat-developer/vscode-java#620

  10. andxu commented on Nov 1, 2018

    @andxu
    Contributor

    Use redhat-developer/vscode-java#620 to discuss the single file, close this one

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions