Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

this is my launch.json:

"configurations": [
    {
        "type": "java",
        "name": "admin-ui",
        "request": "launch",
        "cwd": "${workspaceFolder}",
        "console": "internalConsole",
        "mainClass": "com.bla.blo.Application",
        "projectName": "admin-ui",
like image 666
Sam Avatar asked Oct 29 '25 11:10

Sam


2 Answers

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.

About you saying:

vscode asks me to specify the main Class for my java configuration

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:

enter image description here

Anyway, the solution is selecting the option which name is in mainClass configuration from the debug drop-down box on the left. From the configuration in your launch.json, you should choose admin-ui.

like image 51
Molly Wang-MSFT Avatar answered Oct 31 '25 23:10

Molly Wang-MSFT


Here you can set the default launch configuration, then after that, you can use F5 to launch the default one.

enter image description here

like image 43
Sheng Chen Avatar answered Oct 31 '25 23:10

Sheng Chen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!