Visual Studio Code + Spring Boot Project change spring.properties.additional-location etc - spring

Recently i decided to pass from Eclipse to VS Code , everything is running smoothly for Javascript development but for Spring Boot applications i don't know how to configure them here .
Except of the application.properties file i have one more extra local.properties which i use to run locally the Spring Boot Application .
I see there is a launch.json file :
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - fmApplication",
"request": "launch",
"mainClass": "com.application.zz.app.fmApplication",
"projectName": "file-manager"
}
]
}
In Eclipse i am adding additional configuration to run my Spring Boot Application like shown below :
How can i do that is Vs Code :) ?
Here is the issue on Vs Code Github Page

Unlike JavaScript, Java code needs to be compiled so it wont work out of the box with visual studio code since it's just a glorified text editor.
There are however multiple tools to accommodate for this, and the folks at VS code
have a nice guide for setting you up - https://code.visualstudio.com/docs/java/java-spring-boot
Solution :
So you have an application.properties file and locally you have a application-local.properties(attention , you must name your local properties like that).
Then in your launch.json you add it to your program parameters :
"args": "--spring.profiles.active=local"
So your launch.json file will look like this for example :
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - fmApplication",
"request": "launch",
"mainClass": "com.intralot.l10.app.fmApplication",
"projectName": "file-manager",
"args": "--spring.profiles.active=local"
}
]
}

Related

Cannot debug Rust in Visual Studio Code?

I am trying to debug a Rust program in VS Code, but I get an error:
After clicking OK, VS Code opens "settings.json":
I have these extensions installed:
My program is a simple "hello world" app.
Unfortunately VS Code can't debug Rust out of the box :( But no need to worry, just few steps of configuration will do the work :)
Steps
Install C/C++ extension if you are on windows and CodeLLDB if on OS X/Linux
Click Debug -> Add Configuration, a launch.json file should open, you need to change the program name here manually
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}/target/debug/foo.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true
},
{
"name": "(OSX) Launch",
"type": "lldb",
"request": "launch",
"program": "${workspaceRoot}/target/debug/foo",
"args": [],
"cwd": "${workspaceRoot}",
}
]
}
Make sure Allow setting breakpoints in any file is checkend under File -> Preferences -> Settings
For detailed steps and more you can refer the article I used to answer this
Credits- Forrest Smith
From your screenshots, you're on Windows, so here's how to proceed. This assumes you already took care of the basics:
VsCode has the recommended rust-analyzer extension installed.
Your project folder was initialized with cargo init. (Your project's folder name must be the same as the name of your package in Cargo.toml.)
You can cargo run from within your project directory and it works.
As indicated by various locations on the 'Net, you need to install another VsCode extension to make it so you can debug. Since you're on Windows, you want to use the MS C++ DevTools extension for VsCode, instead of the CodeLLDB one.
Next, you need a "launch" configuration setup. Select VsCode's Run >>> Add Configuration... menu item. Choose the C/C++: (Windows) launch option in the drop-down. You'll now have a launch.json file with a single configuration object.
You'll need to change the program property to "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe"; this depends on your package name being the same as the project folder's name. (I also changed the cwd property to "${workspaceFolder}", though I'm not sure it matters.) To be clearer, here's the configuration I have presently in my launch.json file (the preLaunchTask property is for later):
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe",
"preLaunchTask": "rust: cargo build",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal"
}
At this point, as long as you've already built your project at least once, you can hit F5 and debug.
If you want F5 to also save your changes and rebuild your project before debugging, then you also have to add a build task and configure it to run before debugging starts.
To do that, add the build task by opening the Show All Commands box (either F1 or Ctrl+Shift+p) and choosing Tasks: Configure Task. Select rust: cargo build. It'll create a tasks.json file next to your launch.json; the defaults are all you need. My file looks like this:
{
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"command": "build",
"problemMatcher": [
"$rustc"
],
"group": "build",
"label": "rust: cargo build"
}
]
}
Then, to hook everything up, you just need to manually add the preLaunchTask property to your launch configuration with a value equal to the label in your task. E.g. "preLaunchTask": "rust: cargo build",, like what I have in my example launch.json up above.
At this point, whenever you press F5, VsCode will save your work, rebuild your project, then start debugging it.
Visual Studio Code is a general editor, but it can be configured to debug rust code.
Step 1.
Assuming that Visual Code, rust and cargo are installed, the first step is to enable the required extensions:
rust-analyzer
CodeLLDB
These only need to be installed one.
Step 2
The second step is to create the rust code. I have a folder called Rust, in which I keep the rust code. Changing to that folder, I use cargo new hello_world to create a new rust project.
Step 3
The third step is to change the folder for the project. There are two plausible options, but only one of them will work.
I changed to my Rust folder, and then I can edit the source code by following ``hello_world - src`.
To debug the code, it is necessary to create a launch.json file, using Run - Add configuration... However, the file isn't correct, with <your program> where the correct name should be. This is the wrong approach.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/<your program>",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
The documentation is a bid thin at this point. The correct approach is to pick a different folder, the top level of the project hello_world. The Cargo.toml file is available.
Now, when Run - Add configuration... is used, and the option of LLDB is selected -
the Cargo.toml file can be picked up -
and then the Cargo.toml file is used to correctly build the launch.json file -
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'hello_world'",
"cargo": {
"args": [
"build",
"--bin=hello_world",
"--package=hello_world"
],
"filter": {
"name": "hello_world",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'hello_world'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=hello_world",
"--package=hello_world"
],
"filter": {
"name": "hello_world",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
Now, both Run - Start debugging and Run - Run without Debugging both work properly.

debug spring project with specific profile on visual studio code

I'm trying to debug a kotlin/spring project in vscode, but I can't find a way to activate the desired profile.
My launch.json file looks like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "kotlin",
"request": "launch",
"name": "Kotlin Launch",
"projectRoot": "${workspaceFolder}",
"mainClass": "my.package.ApplicationKt",
"args": [ "--spring.profiles.active=dev" ]
}
]
}
The app starts but with no active profile. I've seen a lot of answers with different combinations: using vmArgs instead of args, "-Dspring.profiles.active=dev" or [ "--spring.profiles.active", "dev" ] or [ "-Dspring.profiles.active", "dev"] but nothing seems to work.
I'm using VSCode 1.63.0 with kotlin 1.5.30 and spring boot 2.4.4.
I finally figured it out thanks to autocomplete.
VSCode documentation is not ok. All the examples and documentation points to vmArgs option where, supposedly, I could set my -Dspring.profiles.active=dev, but that's not the case, at least for the versions I'm working on.
The correct option is not vmArgs but vmArguments instead.

"You don't have an extension for debugging 'JSON with Comments'" warning when debugging VS Code theme

I generated the files necessary for creating a color theme in VS Code. I did this with the generator-code node package.
My file structure is as follows
When I run VS Code's debugger, I get this warning that prevents the debugger from running.
Here are the contents of my launch.json file for reference:
{
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
}
]
}
In case you're wondering what I'm expecting to happen when I run the debugger, here's the moment in the tutorial I was following where I ran into this problem.
Edit: Well, I evaded the problem somehow by deleting the files and starting over. I'm not sure what was causing the problem before.
This popup only appears for me when trying to launch the debugger while having the launch.json or tasks.json file open. Switching to one of my test files and launching the debugger fixes it
I had this error when my launch.json was not according to the version + configurations scheme, I copy pasted the content of configurations to the file instead of putting it in the array.
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
}

How do you debug the cucumber step definitions w/ Visual Studio Code?

I'm using the protractor-cucumber-framework to create a testbed environment for our QA team. I've searched around and been able to find zero help in implementing VS Code's debugging capability for use in this code. Has anyone does this? I'd really like to step away from console.log() statements.
1) Upgrade your Nodejs to 8 and later
2) Create a folder .vscode under your project base directory
3) Create a file launch.json under .vscode
4) Copy below content into launch.json
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"name": "gie",
"program": "${workspaceFolder}/node_modules/protractor/built/cli.js",
"cwd": "${workspaceFolder}",
"args": [
"config/gie.config.js",
"--browser=chrome"
]
}]
}
The ${workspaceFolder} represent your project base directory
The first value in args is your protractor config file, you can use relative path to ${workspaceFolder}
The second and next value in args is command options as you type in command line to run test.
My Environment: VSCode 1.8.1, Nodejs v8.9.0, Protractor 5.2.0,

Debugging MSTest Unittests in Visual Studio Code

I am trying to use Visual Studio Code to Debug a MSTest unit test project. But the tests just run and the breakpoint is never reached.
Here is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Test (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "C:\\Program Files\\dotnet\\dotnet.exe",
"args": ["test"],
"cwd": "${workspaceRoot}",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
How can I debug a unit test (MSTest)? This same problem exists for XUnit.
If you are using the latest version of VS Code (I'm using v1.29.0), debugging unit test is in-built feature.
You need to first build the solution dotnet build for the test run & debug options to appear.
Try https://github.com/Microsoft/vstest-docs/blob/master/docs/diagnose.md#debug-test-platform-components (assumes you're using dotnet-cli tools 1.0.0)
> set VSTEST_HOST_DEBUG=1
> dotnet test
# Process will wait for attach
# Set breakpoint in vscode
# Use the NETCore attach config from vscode and pick the dotnet process
Try and reload VS Code, worked for me.
Press Ctrl+Shift+P which opens the command palette and then :
Reload Window
Before building, remember to include in your .csproj file
<GenerateProgramFile>false</GenerateProgramFile>
or else it will not know what to run...
Program.cs(160,21): error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point. [/Users/.../Fraction.csproj]

Resources