简体   繁体   English

如何在 vscode 中设置 launch.json 中的默认 java 配置,以使 vscode 在每次运行应用程序时停止要求我指定主类?

[英]How can I set in vscode a default java configuration in launch.json to make vscode stop asking me to specify a main class every time I run the app?

every time I start my Java application, vscode asks me to specify the main Class for my java configuration, even though I already did it in launch.json.每次我启动我的 Java 应用程序时,vscode 都会要求我为我的 Java 配置指定主类,即使我已经在 launch.json 中这样做了。 bit i believe what it's asking me is to choose a certain configuration to run from.我相信它要求我选择某种配置来运行。 so my question is:所以我的问题是:

is there a way to make a default Configuration to run from in launch.json?有没有办法让默认配置从launch.json中运行?

this is my launch.json:这是我的launch.json:

"configurations": [
    {
        "type": "java",
        "name": "admin-ui",
        "request": "launch",
        "cwd": "${workspaceFolder}",
        "console": "internalConsole",
        "mainClass": "com.bla.blo.Application",
        "projectName": "admin-ui",

Here you can set the default launch configuration, then after that, you can use F5 to launch the default one.在这里你可以设置默认启动配置,然后你可以使用F5启动默认配置。

在此处输入图片说明

If a class is kind of public and includes the function public static void main(String[] args) , java extension will recognize it as mainClass and auto-complete it in launch.json.如果一个类是public类并且包含函数public static void main(String[] args) ,java 扩展会将其识别为mainClass并在 launch.json 中自动完成它。

About you saying:关于你说:

vscode asks me to specify the main Class for my java configuration vscode 要求我为我的 java 配置指定主类

It's may because when your debugging option is Current File ,you have more than one mainclass, so java extension will ask you to select one to run:这可能是因为当你的调试选项是Current File 时,你有多个主类,所以 java 扩展会要求你选择一个来运行:

在此处输入图片说明

Anyway, the solution is selecting the option which name is in mainClass configuration from the debug drop-down box on the left.无论如何,解决方案是从左侧的调试下拉框中选择namemainClass配置中的选项。 From the configuration in your launch.json, you should choose admin-ui .从 launch.json 中的配置中,您应该选择admin-ui

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 vscode java launch.json 参数 - vscode java launch.json args Java-VSCode 错误:无法自动解析模块路径/类路径,请在启动时指定值。json - Java-VSCode error:Cannot resolve the modulepaths/classpaths automatically, please specify the value in the launch.json Minimumn launch.json inside.vscode 目录,用于运行 maven 项目的主 class(使用“F5”) - Minimumn launch.json inside .vscode directory for running main class of a maven project (with `F5`) VSCode Java扩展launch.json设置问题 - VSCode Java Extension launch.json setup problems 如何在 VSCode 中将 VM 参数从 launch.json 传递到 Junit Test 类? - How to pass VM arguments from launch.json to Junit Test class in VSCode? 如何使用 VSCode 在没有 main 方法的情况下执行 java 程序? - How can I execute a java program without a main method with VSCode? 将Spring参数添加到VSCode Debug launch.json - Adding Spring arguments to VSCode Debug launch.json 将当前项目添加到vscode launch.json“ classpaths”字段 - Add current project to vscode launch.json “classpaths” field 如何向 VSCode Java 调试器提供启动选项参数 - How do I provide launch option args to VSCode Java Debugger 我如何 map 从 IntelliJ 到 VSCode 的运行配置? - How do I map the Run Configuration from IntelliJ to VSCode?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM