I want to create a Java execution environment in VScode (execute Java commands within built-in terminals, enable automatic formatting)

Asked 2 years ago, Updated 2 years ago, 54 views

ThinkpadX270/alter linux
VScode 1.67.2
java-version

openjdk version "18.0.1.1" 2022-04-22
OpenJDK Runtime Environment (build 18.0.1.1+2)
OpenJDK64-Bit Server VM (build 18.0.1.1+2, mixed mode)

I would like to do the following with VScode
·Enable predictive conversion and automatic formatting
·Run from terminal within VScode

First, you cannot run from a terminal in VScode.
The java command fails to run a class that runs print only.The following log

 sh:java: command not found

In addition, a pop-up to the effect that you want to get jdk will appear.

Check for enhancements
Verified the Java Extension Pack is installed.Reinstalled.

Run test print class from individually launched terminals
Success.

Verify Path
You should be looking at the same path as the individually booted terminal, but the java command is not executed from the terminal in VScode.

The following is done from a terminal in VScode

sh-5.1 $which java
which —no java in (/app/bin:/app/bin:/app/bin:/usr/bin:/home/a7uku/.var/app/com.visualstudio.code/data/node_modules/bin)

Run from within individually launched zsh

 w which java
/usr/bin/java

## Action to receive comments

/bin/zsh
/usr/bin/zsh

2. Start sh, bash from terminal (not vscode integration), check java command
Start both sh and bash, java Command Test Successful

The executable seen inside the VScode looks different.
There appears to be a problem referencing /usr/bin/java as an alias.

java linux vscode

2022-09-30 19:34

1 Answers

The name of the shell you are currently using appears in the upper right corner, so please check if it is zsh.
Probably not zsh, so please open the pulldown menu to the right of the + icon and select zsh.

A new terminal will open, so try running the java command. If you have configured the PATH in .zshrc (such as zsh specific configuration files), you should be able to pass the command.

If there is no problem, change the shell that starts by default from Select Default Profile in the same pulldown menu to zsh.

Note: Integrated Terminal in Visual Studio Code

Enter a description of the image here


2022-09-30 19:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.