参考
环境
环境 | 版本 | 说明 |
---|---|---|
windows | 10 | |
vs code | 1.85.1 | |
Spring Boot Extension Pack | v0.2.1 | vscode插件 |
Extension Pack for Java | v0.25.15 | vscode插件 |
JDK | 11 | |
Springboot | 2.3.12.RELEASE | |
Apache Maven | 3.8.6 |
正文
精简版:设置项目中 .vscode\launch.json
(文件不存在就通过左侧菜单->运行和调试->创建launch.json文件
->选择 Java) 的数组 configurations
,添加 args
与 vmArgs
键,值为字符串(字符串前后加空格),然后保存,最后在左侧菜单 Spring Boot Dashboard
(这是插件,参考环境中安装的插件安装即可) 中运行项目即可。
实现要求
- 添加 VM 参数。
- 添加启动参数。
步骤
-
VS Code 打开项目
-
左侧菜单栏选择 运行和调试。
-
点击
创建launch.json文件
,后选择 Java。
-
自动生成如下配置,由于我是多模块
configurations
会生成多个,单模块的话configurations
就是一个:{ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "java", "name": "Current File", "request": "launch", "mainClass": "${file}" }, { "type": "java", "name": "ConsumerApplication", "request": "launch", "mainClass": "com.xiaqiuchu.consumer.ConsumerApplication", "projectName": "consumer" }, { "type": "java", "name": "ProviderApplication", "request": "launch", "mainClass": "com.xiaqiuchu.provider.ProviderApplication", "projectName": "provider" }, { "type": "java", "name": "RegistryApplication", "request": "launch", "mainClass": "com.xiaqiuchu.registry.RegistryApplication", "projectName": "registry" } ] }
-
给每个模块配置项添加
args
与vmArgs
字段,其中args
是启动参数,vmArgs
是 VM 参数。(参数为字符串形式,前后加上空格防止命令拼接的时候将命令拼接为字符串而导致不识别){ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "java", "name": "Current File", "request": "launch", "mainClass": "${file}" }, { "type": "java", "name": "ConsumerApplication", "request": "launch", "mainClass": "com.xiaqiuchu.consumer.ConsumerApplication", "projectName": "consumer", "args": "", "vmArgs": "", }, { "type": "java", "name": "ProviderApplication", "request": "launch", "mainClass": "com.xiaqiuchu.provider.ProviderApplication", "projectName": "provider", "args": "", "vmArgs": "", }, { "type": "java", "name": "RegistryApplication", "request": "launch", "mainClass": "com.xiaqiuchu.registry.RegistryApplication", "projectName": "registry", "args": "", "vmArgs": "", } ] }
-
左侧菜单
Spring Boot Dashboard
中启动项目(这是插件,参考环境中安装的插件安装即可)。
演示
我这里设置的是 skytalking 相关 VM 配置。
{
"configurations": [
{
"type": "java",
"name": "Spring Boot-ConsumerApplication<consumer>",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "com.xiaqiuchu.consumer.ConsumerApplication",
"projectName": "consumer",
"args": "",
"envFile": "${workspaceFolder}/.env",
"vmArgs": " -javaagent:C:\\apache-skywalking-java-agent-9.1.0\\skywalking-agent\\skywalking-agent.jar -Dskywalking.agent.service_name=consumer"
},
{
"type": "java",
"name": "Spring Boot-ProviderApplication<provider>",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "com.xiaqiuchu.provider.ProviderApplication",
"projectName": "provider",
"args": "",
"envFile": "${workspaceFolder}/.env",
"vmArgs": " -javaagent:C:\\apache-skywalking-java-agent-9.1.0\\skywalking-agent\\skywalking-agent.jar -Dskywalking.agent.service_name=provider"
},
{
"type": "java",
"name": "Spring Boot-RegistryApplication<registry>",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "com.xiaqiuchu.registry.RegistryApplication",
"projectName": "registry",
"args": "",
"envFile": "${workspaceFolder}/.env",
"vmArgs": " -javaagent:C:\\apache-skywalking-java-agent-9.1.0\\skywalking-agent\\skywalking-agent.jar -Dskywalking.agent.service_name=registry"
}
]
}
标签:Code,java,name,launch,Spring,agent,参数,mainClass,com
From: https://www.cnblogs.com/xiaqiuchu/p/17932120.html