Vishnu Joshi
Vishnu Joshi

Reputation: 333

JAVA : Program Works in Terminal , But not in Visual Studio Code : Mac OS

My JAVA Programs used to run without any errors on both the Terminal and Visual Studio Code's Terminal .

After my Mac updated to MacOs Big Sur Version 11.0.1 , my JAVA programs show an error , even though the same code worked properly before .

enter image description here

enter image description here

There was no error before.

I checked my JDK and JRE Installations also

enter image description here

My Python files execute normally in the VS Code environment , so I do not think there is a problem with VS Code .

I have tried searching for an solution and have tried to clear the logs.

enter image description here

I would appreciate if anyone could guide me :)

Upvotes: 2

Views: 4251

Answers (5)

Antact
Antact

Reputation: 89

I faced a similar problem. When running the same Java program, it worked in terminal but VS Code couldn't detect java.

All it turned out to be was I forgot to add Code itself to Path after reinstallation, nothing to do with Java.

Upvotes: 0

ligenboboqiu
ligenboboqiu

Reputation: 1

Hi just found a solution here! Initially guess it should be a problem with zsh. so first open your terminal and type

open ~/.zshrc

at this point you will see text editor pops up with a zsh config file.

Add

export JAVA_HOME=`/usr/libexec/java_home

to the last line in that file, and save the file quit.

Then just reopen the VSC and you will notice everything would back to normal as usual.

Upvotes: 0

Molly Wang-MSFT
Molly Wang-MSFT

Reputation: 9521

  1. Run the .java file in Terminal to check if JDK can work normally:

     javac Hey.java
     java Hey
    
  2. If there's nothing wrong with the above command execution, turn to VS Code, uninstall Java Extension Pack and also delete the related folders under User/name/.vscode/extensions, then reinstall it again;

  3. Set java.home and java.configuration.runtimes in User Settings.json.

Reference: Configure JDK.

Then run the project again to see if the problem goes away.

Upvotes: 2

Leotrim Vojvoda
Leotrim Vojvoda

Reputation: 406

You need to install the java plugin in VS Code.

Upvotes: 0

Goutham Rajeev
Goutham Rajeev

Reputation: 40

Install Java by searching for extensions in VSCode and try to run again.It will be executed. I belive it is not installed

Upvotes: 0

Related Questions