How to configure VS Code to run JAVA programs with MAVEN passing parameters?

Asked

Viewed 628 times

2

I have a code with no main method. The project is executed using the following command:

$mvn clean install -Dparam1="folder" -Dparam2="path"

In Eclipse or Intellij, I just need to create a Maven executor, set the goals as clean installation and pass the parameters of the Maven at the right place.

In Vscode, I saw three different approaches and tried them:

  1. Creating a file launch.json calling the command mvn in preLaunchTask.
{
  "version": "0.2.0",
  "configurations": [
    {
        "type": "java",
        "request": "launch",
        ...
        "preLaunchTask": "mvnDebug",
        "vmArgs": [ "clean", "install", "-Dparam1=\"blabla\"", "-Dparam2=\"blablabla\"" ]

    }
  ]
}

I also tried to pass all commands on prelaunchTask without the parameter vmArgs. And it didn’t work.

  1. Creation of a task.json passing the script, and a launch.json who will call on prelaunchTask the task created with the name defined in the parameter"taskName"of the task.
{
    "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": []
        }
    ]
}

The third approach I used is through settings.json:

{
    "maven.terminal.favorites": [
        {
            "alias": "CLEAN COMPILE",
            "command": "clean install -Dparam1=\"value\" -Dparam2=\"blabla\"",
            "debug": true
        },
    ]
}

For all of them I got the result in terminal:

Listening for transport dt_socket at address: 56787

What I need is:

  1. What does this mean? Why are you waiting for a port? How does Vscode use a socket to do this?
  2. What is the best approach and why?
  3. How to run my code in Vscode? This is the most important one! I need to run my code.
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.