Reputation: 5542
I'm trying to debug my Java project in vscode. I added a launch.json file that looks like this:
"configurations": [
{
"type": "java",
"name": "Debug with args",
"args": "--args_for_app",
"classPaths": ["$HOME/bin/some.jar", "$HOME/bin/some_other.jar"],
"env": {
"env1": "env1value"
},
"request": "launch",
"mainClass": "my.main.ClassName",
"projectName": "projectName",
"console": "internalConsole"
}
]
If I remove the classPaths
field, vscode automatically resolves the current project into the classpath, and the debugger starts successfully, but I need to also add other jar files into classpath. If I add the field with my desired jar paths, vscode no longer resolves the project's path automatically (which makes sense), but now I don't know how to add it back to the list.
I tried adding "."
, "${file}"
, and "${workspace}"
, none worked. I still get an error saying the main class can't be found:
Error: Could not find or load main class my.main.ClassName
Caused by: java.lang.ClassNotFoundException: my.main.ClassName
Upvotes: 3
Views: 11834
Reputation: 1469
So the main problem is to add jar as the dependency, right? Please have a look at the official doc: https://code.visualstudio.com/docs/java/java-project#_standalone-java-file-support
A function has been added to specify the jar files as the library.
Here is the edit, we can do the following to add jars/lib in VSCode:
Add your .jar file into a ./lib
in your project root.
Configure paths in the .classpath to point to your jars, like:
<classpathentry kind="lib" path="lib/my.jar"/>
The VS Code user workspace storage area can be found under these locations :
Windows : %APPDATA%\Code[ - Variant]\User\workspaceStorage\
MacOS : $HOME/Library/Application Support/Code[ - Variant]/User/workspaceStorage/
Linux : $HOME/.config/Code[ - Variant]/User/workspaceStorage/ could refer to add jar
Upvotes: 2