问题
I am using Visual Studio Code 0.9.2 on OS X Yosemite to edit a .java file.
I attempt to compile this file using the following tasks.json file:
{
"version": "0.1.0",
"command": "javac",
"isShellCommand": true,
"echoCommand": true,
"showOutput": "always",
"args": ["-d","${workspaceRoot}\/target","${workspaceRoot}\/src\/*.java"]
}
Executing this task echoes the following command to the Output window:
running command$ javac -d /Users/caoimheboers/Desktop/JLab11/target
/Users/caoimheboers/Desktop/JLab11/src/*.java
... which is fine, however the result of the task execution is then reported as:
javac: file not found: /Users/caoimheboers/Desktop/JLab11/src/*.java
Usage: javac <options> <source files>
use -help for a list of possible options
I have tried the following:
Copy the echoed javac command (including all arguments) from the Output window and paste it to the command line in a Terminal window. Result: The single .java file in the /src folder compiles and a .class file appears in the /target folder. This indicates that the syntax of the javac command (including all arguments) is correct in the tasks.json file.
In the tasks.json file, replace the wildcard character with the name of the single .java file in the /src folder. Result: The VS Code task runs perfectly, and produces a .class file in the /target folder. This indicates that everything about the command in the tasks.jason file is OK except for the wildcard character.
Any ideas on what I'm doing wrong?
回答1:
I also experienced it, it was apparently a bug. Currently there is a new terminal runner which fixes this error. Try to change the tasks JSON schema to new 2.0.0 version, reload the window and everything will be fine:
{
"version": "2.0.0",
"command": "javac",
"isShellCommand": true,
"echoCommand": true,
"showOutput": "always",
"args": ["-d","${workspaceRoot}/target","${workspaceRoot}/src/*.java"]
}
The related issue is here: https://github.com/Microsoft/vscode/issues/16865
You don't need to escape the slash character by the way.
来源:https://stackoverflow.com/questions/33698512/task-command-using-wildcards-in-arg-in-visual-studio-code