How to add JVM arguments for Spring Boot project in VS Code?
Asked Answered
P

3

21

I'm trying out VS Code by moving a project I did on Eclipse to it. I had a run configuration in Eclipse for this project which had the following JVM arguments:

--module-path lib/javafx-sdk-13/lib --add-modules=javafx.controls

Of course this "lib" folder and its contents followed to the new VS Code project folder but I don't know where to put those JVM arguments in vsCode, the equivalent of the run configurations with Eclipse essentially. I tried putting them in the args section of the launch.json file with no success.

I am using the spring boot dashboard to launch the project if that makes a difference.

Here is my launch.json:

{
"configurations": [
    {
        "type": "java",
        "name": "Spring Boot-BudgetApplication<budget>",
        "request": "launch",
        "cwd": "${workspaceFolder}",
        "console": "internalConsole",
        "mainClass": "com.someone.budget.BudgetApplication",
        "projectName": "budget",
        "args": ["--module-path","lib/javafx-sdk-13/lib","--add-modules=javafx.controls"]
    }
]

}

Peshawar answered 3/2, 2020 at 16:10 Comment(13)
Even just running the main method without the spring boot dashboard does not work.Peshawar
-DARG_NAME=ARG_VALUE I.e.: -Dhttp.proxy="myproxy.url"Contortionist
is that not just for Spring properties? Not sure how that would translate to JVM arguments to point to the JavaFX files and add the controls module?Peshawar
JVM Args are quite simple --ARG is destinated to the Jar you run, -DargName is an JVM Argument. Keep in mind, your code (your jar) can access the JVM Args.Contortionist
is this the right syntax? "args": "-D--module-path lib/javafx-sdk-13/lib --add-modules=javafx.controls"Peshawar
Nop -Dmodule-path=lib/javafx-sdk-13/lib -Dadd-modules=javafx.controls maybe --Dmodule-path=lib/javafx-sdk-13/lib --Dadd-modules=javafx.controlsContortionist
none of those workPeshawar
No, --module-path is a regular argument of the Java command. Whatever is passed to -D becomes a system property. There is a whole lot of miscommunication going on here and a whole lot of guess work. I think the arguments deal is a big red herring, isn't this a more generic "How do I get stuff to run using the Spring Boot Dashboard VSC plugin" ? If so... you must be getting an error of some kind, so share it.Hoahoactzin
Does it work if you just run the app outside of VSCode ?Contortionist
"Error: JavaFX runtime components are missing, and are required to run this application". Typical "I don't know where the libs are" error.Peshawar
this app works perfectly in eclipse because i can just add those arguments in the run configuration's JVM argumentsPeshawar
Ok, so your problem is into the VSCode plugin.Contortionist
It is not, as I get the same issue just running the main method normally without the plugin. Again, I just need to know how to pass JVM arguments to a Java app with vsCode. If it can at least run I'll worry about the spring boot dashboard plugin later.Peshawar
P
27

The solution was placing the args in the vmArgs section like so :

"vmArgs": "--module-path=lib/javafx-sdk-13/lib --add-modules=javafx.controls"
Peshawar answered 3/2, 2020 at 17:14 Comment(4)
This works with the spring boot dashboard plugin as well btw.Peshawar
Could you please add steps Where to add this?Pashalik
@MehrajMalik In the project's launch.jsonBishopric
beware if your vmargs is a long string, you cannot break into multiple lines as json specs dont allow. Just use the long single line.Cranford
C
5

Just add it in the launch.json file.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Application",
            "request": "launch",
            "mainClass": "mypackage.Application",
            "projectName": "myproject",
            "vmArgs": "-Darg1=60000 -Darg2=120000"
        }
    ],
}
Consensual answered 6/12, 2022 at 1:5 Comment(0)
S
3

I know this question was for springboot, but wanted to add for standalone java apps, you can just add args to launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Application",
            "request": "launch",
            "mainClass": "mypackage.Application",
            "projectName": "myproject",
            "args": ["60000","120000"]
        }
    ],
}
Seeseebeck answered 21/2 at 17:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.