问题
I am using Visual Studio Code to run a simple Java "Hello World" program. But I also get some long codes before my output "Hello, World!".
myusername hi % cd /Users/myusername/Desktop/Programming/hi ; /Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:51164 --enable-preview -XX:+ShowCodeDetailsInExceptionMessages -Dfile.encoding=UTF-8 -cp "/Users/myusername/Library/Application Support/Code/User/workspaceStorage/9d9a27fdd962858fd296255e0827be55/redhat.java/jdt_ws/hi_a18a0468/bin" App Hello, World!
I don't really understand these codes before or the reason for it, is that normal? How could I remove these codes from my terminal and make my output simple?
回答1:
These are execution scripts and VS Code displays them to let developers know what's going on during this process, including
the current used JDK:
Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home/bin/java
network and displaying message rules:
agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:51164 --enable-preview -XX:+ShowCodeDetailsInExceptionMessages -Dfile.encoding=UTF-8 -cp
classpath and cache location:
/Users/myusername/Library/Application Support/Code/User/workspaceStorage/9d9a27fdd962858fd296255e0827be55/redhat.java/jdt_ws/hi_a18a0468/bin
the name of current .java file:
App
There're some ways to get clear output without these scripts:
- Set
"console": "internalConsole"
in launch.json, the result will be displayed in Debug Console:
- Set
"console": "externalTerminal"
in launch.json, the result will be displayed in the new opened terminal:
Install Code Runner and add the following code in Settings.json, the result will be shown purely in OUTPUT:
"code-runner.clearPreviousOutput": true, "code-runner.showExecutionMessage": false,
回答2:
MacOS set default Java (JDK) Open Terminal
Step 1. /usr/libexec/java_home -V
Step 2. export JAVA_HOME=/usr/libexec/java_home -v 1.8
Step 3. java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
Up:~ xxx$
Good jobs.
来源:https://stackoverflow.com/questions/64776510/long-codes-before-output-in-vscode-java