I have a code without main method. The project was executed using the following command:
$mvn clean install -Dparam1="folder" -Dparam2="path"
In Eclipse or IntelliJ, I just need to create a maven executor, define the goas as clean install and pass the maven parameters using the -Dparam format.
In VSCode, I have saw 3 different approaches and experimented the following:
lunch.json file calling the command mvn or mvnDebug in the preLaunchTask.{
  "version": "0.2.0",
  "configurations": [
    {
        "type": "java",
        "request": "launch",
        ...
        "preLaunchTask": "mvnDebug",
        "vmArgs": [ "clean", "install", "-Dparam1=\"blabla\"", "-Dparam2=\"blablabla\"" ]
    }
  ]
}
I also have tested passing all the commands in the preLaunchTask without the vmArgs. And did not work.
task.json file passing the script and a launch.json file which will call in preLaunchTask the task created with the name defined in the parameter taskName of task.json.{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "request": "launch",
            "preLaunchTask": "Debug",
            "name": "Launch Program",
            "sourceMaps": true
        }
    ]
And the tasks.json:
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Debug",
            "type": "java",
            "script": "mvnDebug clean install -Dparam1=\"folderName\" -Dparam2=\"blablabla\"",
            "problemMatcher": []
        }
    ]
}
settings.json:{
    "maven.terminal.favorites": [
        {
            "alias": "CLEAN COMPILE",
            "command": "clean install -Dparam1=\"value\" -Dparam2=\"blabla\"",
            "debug": true
        },
    ]
}
For all of them I got the message in the terminal:
Listening for transport dt_socket at address: 56787
What I need from you, guys, is:
OBSERVATION: My JAVA version is JDK11, but I've tried with JDK 8 too.
Thank you a lot.
1.In launch.json, the attribute vmArgs is
The extra options and system properties for the JVM (for example -Xms -Xmx -D=), it accepts a string or an array of string. debugging-launch
so it won't work for your application.
2.In tasks.json, the attribute command is for the command to execute;
Custome Tasks
3.It's recomended to use the setting maven.executable.options
, which specifies default options for all mvn commands.
vscode-maven

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