VS Code Java Debugger - java

I installed VS Code Java Debugger and loaded my Java project.
Add Configuration:
I tried to add configuration by clicking the button as shown in above image.
Activating Extensions:
When I click Add Configuration, I get Activating Extensions like above and that's it.
Sometimes I get "The Language Support for Java crashed 5 times in the last 3 mins."
How do I setup the Java Debugger in VSCode?
Note : I Uninstalled VSCode, deleted the extensions from %Users%/.vscode/extensions and reinstalled VSCode and extensions. The issue still exists.

For me, the following actions fixed this issue:
Un-install all Java related extensions.
Re-install the Java Extension Pack only.
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack

I was facing the same kind of error but one day found a solution
https://stackoverflow.com/a/61806765/5108695
Basic idea is to:
Install an extension called Lombok Annotations
https://marketplace.visualstudio.com/items?itemName=GabrielBB.vscode-lombok
After installation of this extension, my Java code is able to run and debug in VSCode.
PS: Make sure you had insalled Java Extension pack
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack

Related

what should java.testMethod be set to for vscode to run junit tests

vscode 1.52 redhat 7.7
I believe I have all the extensions I need installed ( although the maven extension failed to install it looks like the pom file was read ). When I open a junit test case I see "run all Tests". When I select it I get an error
set "java.testMethod"" in ./vscode/settings.json
I've searched the web and the vscode documentation but am not finding a reference to java.testMethod so I don't have any idea what to set it to. I am also puzzled that it refers to .vscode/settings.json when that file is under .config/Code/User
I have met the same problem. And it was solved. The reason is that the class did not import the reference. You can check it.
Had very similar issue and it turns out finally that some extensions which I unconsciously installed were fine by the time there was an update.After reintsalling only needed extensions all went back to working mode.Be sure the Test Runner for java (should be in Extension Pack for Java) is enabled.

Java "'java.execute.workspaceCommand' failed" in VSCode

I recently wanted to try Java, so i started out with Hello World! I installed OpenJDK 11 for VSCode and ran the program, but it produced the following error:
Running the contributed command: 'java.execute.workspaceCommand' failed.
I looked at the Java runtime configuration and it detected the JDK, but it showed that error!
Go to extensions tab
Search for Java extension package
Click on disable. If it gets disabled, well and good otherwise a pop-up may appear at the bottom, in the bottom of pop-up, click on disable for all windows or something similar text.
Enable the Java extension package again.
In my case, it worked after step 4, let me know about yours
In VSCode:
Go to "Extensions"
Type "Java Extension Pack"
Uninstall
Install
I had this error, and it disappeared after reloading the window:
<Ctrl-P> Developer: Reload Window
or simply,
<Ctrl-R>
I was running into this problem when something with my maven repository settings was incorrect. When I placed the right settings.xml file in the .m2 directory, I was able to launch the program from vscode.
I could also be related to this issue:
https://github.com/redhat-developer/vscode-java/issues/1929

Java Dependency Viewer not appearing in the Explorer Window of Visual Studio Code. Any command to force toggle the view?

I have the Java Dependency Viewer extension configured in my Visual Studio Code and it used to work perfectly fine. But off late, whenever I open up VSCode and try to work on a Spring/ Maven Project, the Java dependency viewer fails to automatically load up on the explorer window (Waited for half an hour at times).
I have all the other important JAVA extensions already installed including the Language Support for Java(TM) by Red Hat.
Is there a way that I can manually toggle the viewer? Or, use any JSON setting to force rendering the viewer? Any suggestion ?
Note: I have tried disabling and enabling the extension, and I can see the viewer appearing. However, since this change causes the VSCode to reload itself, the IDE goes back to its initial state of not rendering the viewer.
Edit: I have JAVA (jdk-14), VSCode (v1.45.1) and Language Support for Java(TM) by Red Hat (v0.62.0) installed.
Have you tried to open a java file? Because the extension activated depends on the opened filename extension.
From here, you can know in which situations 'java dependency viewer' will get work:
"activationEvents": [
"onLanguage:java",
"workspaceContains:pom.xml",
"workspaceContains:.classpath",
"workspaceContains:build.gradle",
"onCommand:java.project.create"
], from official docs you can get to know the significance of every configuration.
But it's rare to miss all the conditions, so it's just in case. Then it looks more like there are some problems with the 'java dependency viewer' extension. you can reinstall it.

Visual Studio Code - Java - Import Errors and More

Just starting working on an existing project at work and wanted to use Visual Studio Code as my IDE (I have used it for a recent Rails project and loved it, so wanted to try with Java).
However, whenever I try to open one of the projects I receive a ton of different errors including:
When importing java.io, java.util, or anything similar, the error:
"The import of java.io (or java.util) cannot be resolved"
Existing classes have an error:
"The implicit super constructor is undefined for default constructor. Must define explicit constructor"
Other random "cannot resolve to a type" errors.
All of these seem to stem from some sort of setting error I have with VS Code but can seem to find what it is. I have already uninstalled and reinstalled the RedHat plug-in that enables the Java language for VS Code.
I have tried setting the java_home setting in the extension to the direct location of the install but that didn't work. Tried uninstalling and reinstalling java and that also didn't work.
My operating specs are as follows:
OS: macOS Sierra
VS Code version 1.15.1
JDK version 1.8.0.144
Any idea on what may be causing this? Do you think it may be an error in how I have VS Code set up or if it's an error (or rather incompatibility) with how the existing project is set up?
I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.
I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory
Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).
As already mentioned previously, you require to clean the project, but that is a bit difficult thing because every folder is a Guid, and you do not know which one to clear, thus requiring you to delete everything. Starting with 0.33.0 version of the plugin you can automatically do that from within the IDE as well, use CTRL + Shift + P and type, java clean, and IDE will show you the suggestion tip for, Java: Clean the Java language server workspace. Upon selection, agree and restart the IDE. It will clean the language server workspace for you.
Another approach can be, the Maven tools within the IDE. If you have this plugin installed, you can use the side bar and utilize the Maven project helper options to perform actions like, clean, install, and package etc. For example, here is the project I am having and the options this shows,
That can be used, graphically, to manage your Maven-based projects. Also, this would work with the Java Extension Pack, not sure yet as to how it would behave with other extensions.
For me: CMD + Shift + P
Then type "Java: Clean Java language Server Workspace"
Note: This will reload/restart vscode as well.
Update:
This appears to not fix it anymore for me. In my case I am using a gradle project, and needed to set the rootProject.name in the settings.gradle to be the same as the folder name that the project is in.
I faced this issue after creating a whole Java project in one computer and then trying to run it on another computer.
After doing everything said in the other answers, what really made VS Code compile was to open each single project java file in VS Code and save it (a simple Ctrl + S). Maybe there is a simpler way of doing it, but that is what worked for me and I hope this helps anyone stuck in this issue.
Press ctrl+shift+p
then search 'java clean' and click 'java: clean java language server workspace' then click restart IDE.
I found another simple trick at least to get rid of "cannot be resolved to a type" errors which were coming from older workspaces and wrong project files I guess?. I just ran an empty main(), with the body commented out, while still keeping my local package / import commands at the start - no errors. After commenting in again, the project compiled without errors. Perhaps this refreshing effect might also help in this context?
I had to clean this folder to get it working on Windows
%APPDATA%\code\Local Storage

Eclipse - Unable to install breakpoint in a Java API Class

I have found a few question about the issue here on StackOverlow, but all were about own written code. My problem is a bit different, because I want to debug a Java API class, named javax.swing.JComponent.
My first problem was, that I couldn't see any sources. I fixed it described like here Attach the Java Source Code by attaching the source to rt.jar.
Now I see the source and I want to set a breakpoint in the JComponent class. If I try so, I get the error message:
"Modify compiler options to generate line number attributes". That is a nice proposal. But my JDK version was already compiled when I downloaded it..
So, do I have it to compile on my own? Or do you have other advices?
Thanks for your help!
P.S.: I have installed
- Eclipse Neon
- jdk1.8.0_91
- Windows 10 (64 Bit)
One probable issue could come from your application server in IDE pointing to JRE instead of JDK.
Try verifying:
Window -> Preferences --> Server --> runtime environments
<Your-Application-Server> --> edit
Select a JDK instead of JRE
Not sure if you have gone through this link.... has few solutions which worked for some.
Eclipse - Unable to install breakpoint due to missing line number attributes
this happens when you use JRE on your build path in this case.
Try do this:
Window -> Preferences --> Java --> Installed JRES-->then use jdk as default JRE
problem fixed!

Categories