英文:
In VSCODE how to run a task automatically when a source file is edited?
问题
在Visual Studio Code(VSCode)中,使用一个名为sfeaapp
的Maven化Java Web应用程序,每当更改sfeaapp
项目的源代码或资源时,如何自动执行mvn package
任务?
我在tasks.json
中定义了以下任务,但我不知道如何使它在编辑并保存项目文件(例如.jsp
文件)时自动触发:
{
"version": "2.0.0",
"tasks": [
{
"label": "auto package",
"type": "shell",
"command": "mvn package -f C:\\VSCODE_PROJECTS\\sfeaapp\\pom.xml",
"args": [],
"group": "build",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"problemMatcher": []
}
]
}
如果我手动启动任务auto package
,它可以正常工作。
英文:
In Visual Studio Code (VSCode), working with a mavenized Java web application, which I call sfeaapp
project.
What can be done so that every time a source or resource of that sfeaapp
project is changed, the mvn package
task is automatically executed?
I have defined the following task in tasks.json
, but I don't know how to make it fire automatically when I edit and save a project file, for example a .jsp
:
{
"version": "2.0.0",
"tasks": [
{
"label": "auto package",
"type": "shell",
"command": "mvn package -f C:\\VSCODE_PROJECTS\\sfeaapp\\pom.xml",
"args": [],
"group": "build",
"presentation": {
"reveal": "always",
"panel": "shared"
},
"problemMatcher": []
}
]
}
The task auto package
works fine if I launch it explicitly.
答案1
得分: 1
使用扩展multi-command,您可以重新定义Ctrl+S
键绑定以保存文件并在稍等片刻后调用任务。
在您的keybindings.json
中添加以下内容:
{
"key": "ctrl+s",
"command": "extension.multiCommand.execute",
"args": {
"interval": 1000,
"sequence": [
"workbench.action.files.save",
{ "command": "workbench.action.tasks.runTask",
"args": "auto package" }
]
},
"when": "resourceDirname == /users/mememe/project/src"
}
将目录调整为工作区目录路径。
英文:
with the use of the extension multi-command you can re-define the keybinding for Ctrl+S
to save the file and call the task after a small wait.
Add to your keybindings.json
{
"key": "ctrl+s",
"command": "extension.multiCommand.execute",
"args": {
"interval": 1000,
"sequence": [
"workbench.action.files.save",
{ "command": "workbench.action.tasks.runTask",
"args": "auto package" }
]
},
"when": "resourceDirname == /users/mememe/project/src"
}
Adjust the directory to the workspace directory path.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论