6

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!

MaxMobileYT
  • 61
  • 1
  • 2
  • How about running your code in external Terminal? use `javac Helloworld.java` to generate .class file. Then run `java Helloworld` to show result. if there's no error shown, try to **clean java workspace** and reinstall [Java Extension Pack](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) in VS Code. – Molly Wang-MSFT Mar 17 '21 at 07:54
  • @MollyWang it says in the terminal could not find or load main Class Helloworld, what does this mean? – MaxMobileYT Mar 19 '21 at 03:45
  • Can you show the error screenshots? both the folder structure in vscode and the error in external terminal. please provide as much information about your question as possible. – Molly Wang-MSFT Mar 19 '21 at 03:51

5 Answers5

6
  1. Go to extensions tab
  2. Search for Java extension package
  3. 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.
  4. Enable the Java extension package again.

In my case, it worked after step 4, let me know about yours

user9072810
  • 61
  • 2
  • 4
0

In VSCode:

  1. Go to "Extensions"
  2. Type "Java Extension Pack"
  3. Uninstall
  4. Install
gabriel-pimentel
  • 81
  • 1
  • 1
  • 9
0

I had this error, and it disappeared after reloading the window:

<Ctrl-P> Developer: Reload Window

or simply,

<Ctrl-R>
Greg
  • 2,476
  • 4
  • 22
  • 28
0

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

Keshav
  • 4,408
  • 8
  • 31
  • 50
0

If you are facing this error around the time of this post March 2023, there is a bug in vscode-java-dependency extension. You can either check if you have the latest version or try to install this pre-release, it fixed it for me:

https://github.com/microsoft/vscode-java-dependency/issues/720

Rui Marques
  • 8,567
  • 3
  • 60
  • 91